EXPLAIN select sum(l_extendedprice) / 7.0 as avg_yearly from lineitem, part where p_partkey = l_partkey and p_brand = 'Brand#55' and p_container = 'SM DRUM' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey ); QUERY PLAN -------------------------------------------------------------------------------------------------------------------- Aggregate (cost=6865839.92..6865839.93 rows=1 width=4) -> Nested Loop (cost=0.56..6865792.47 rows=18980 width=4) -> Seq Scan on part (cost=0.00..70626.15 rows=2002 width=4) Filter: ((p_brand = 'Brand#55'::bpchar) AND (p_container = 'SM DRUM'::bpchar)) -> Index Scan using i_l_partkey on lineitem (cost=0.56..3394.10 rows=9 width=12) Index Cond: (l_partkey = part.p_partkey) Filter: (l_quantity < (SubPlan 1)) SubPlan 1 -> Aggregate (cost=117.12..117.14 rows=1 width=4) -> Index Scan using i_l_partkey on lineitem lineitem_1 (cost=0.56..117.05 rows=28 width=4) Index Cond: (l_partkey = part.p_partkey) (11 rows)