您可以在COUNT函数中使用CASE或DECODE语句。
SELECt item_category, COUNT (*) total, COUNT (DECODE (item_status, 'serviceable', 1)) AS serviceable, COUNT (DECODE (item_status, 'under_repair', 1)) AS under_repair, COUNT (DECODE (item_status, 'condemned', 1)) AS condemned FROM mytableGROUP BY item_category;
输出:
ITEM_CATEGORY TOTAL SERVICEABLE UNDER_REPAIR CONDEMNED----------------------------------------------------------------chair5 12 2table5 31 1



