# Task: 015 **Database:** retails ## Question For each industry, show the number of customers that bought part 309 from China. ## Gold Query ```sql WITH industries AS ( SELECT DISTINCT c.c_mktsegment AS industry FROM customer c ), china_customers AS ( SELECT c.c_mktsegment AS industry, COUNT(DISTINCT c.c_custkey) AS customer_count FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey JOIN lineitem l ON o.o_orderkey = l.l_orderkey JOIN partsupp ps ON l.l_partkey = ps.ps_partkey AND l.l_suppkey = ps.ps_suppkey JOIN supplier s ON ps.ps_suppkey = s.s_suppkey JOIN nation n ON s.s_nationkey = n.n_nationkey WHERE l.l_partkey = 309 AND n.n_name = 'CHINA' GROUP BY c.c_mktsegment ORDER BY c.c_mktsegment ) SELECT i.industry, COALESCE(cc.customer_count, 0) AS customer_count FROM industries i LEFT JOIN china_customers cc ON i.industry = cc.industry ORDER BY i.industry; ``` **Execution Result:** | industry | customer_count | |------------|------------------| | AUTOMOBILE | 0 | | BUILDING | 0 | | FURNITURE | 0 | | HOUSEHOLD | 0 | | MACHINERY | 0 | *5 rows*