1
0

tpch_query17.sql 595 B

12345678910111213141516171819202122232425
  1. with q17_part as (
  2. select p_partkey from part where
  3. p_brand = 'Brand#23'
  4. and p_container = 'MED BOX'
  5. ),
  6. q17_avg as (
  7. select l_partkey as t_partkey, 0.2 * avg(l_quantity) as t_avg_quantity
  8. from lineitem
  9. where l_partkey IN (select p_partkey from q17_part)
  10. group by l_partkey
  11. ),
  12. q17_price as (
  13. select
  14. l_quantity,
  15. l_partkey,
  16. l_extendedprice
  17. from
  18. lineitem
  19. where
  20. l_partkey IN (select p_partkey from q17_part)
  21. )
  22. select cast(sum(l_extendedprice) / 7.0 as decimal(32,2)) as avg_yearly
  23. from q17_avg, q17_price
  24. where
  25. t_partkey = l_partkey and l_quantity < t_avg_quantity;