1
0

tpch_query11.sql 624 B

12345678910111213141516171819202122232425262728293031323334353637
  1. drop view q11_part_tmp_cached;
  2. drop view q11_sum_tmp_cached;
  3. create view q11_part_tmp_cached as
  4. select
  5. ps_partkey,
  6. sum(ps_supplycost * ps_availqty) as part_value
  7. from
  8. partsupp,
  9. supplier,
  10. nation
  11. where
  12. ps_suppkey = s_suppkey
  13. and s_nationkey = n_nationkey
  14. and n_name = 'GERMANY'
  15. group by ps_partkey;
  16. create view q11_sum_tmp_cached as
  17. select
  18. sum(part_value) as total_value
  19. from
  20. q11_part_tmp_cached;
  21. select
  22. ps_partkey, part_value as value
  23. from (
  24. select
  25. ps_partkey,
  26. part_value,
  27. total_value
  28. from
  29. q11_part_tmp_cached join q11_sum_tmp_cached
  30. ) a
  31. where
  32. part_value > total_value * 0.0001
  33. order by
  34. value desc;