SELECT p.product_directory_level , COUNT (CASE WHEN p.product_directory_level = 1 THEN 1
ELSE NULL
END) 物资,
COUNT (CASE WHEN p.product_directory_level = 2 THEN 1
ELSE NULL
END) 大类,
COUNT (CASE WHEN p.product_directory_level = 3 THEN 1
ELSE NULL
END) 中类,
COUNT (CASE WHEN p.product_directory_level = 4 THEN 1
ELSE NULL
END) 小类,
COUNT (CASE WHEN p.product_directory_level = 5 THEN 1
ELSE NULL
END) 细类
FROM pl_product_directory p GROUP BY p.product_directory_level ORDER BY p.product_directory_level ;
使用select case when 语句就能轻松搞定