提示:使用case when
例:
SELECT MIN(province_id) provinceNumber, MIN(province_name) provinceName, COUNT(project_id) a, SUM(this_issue_money) b, SUM(CASE WHEN is_not_exit = true THEN 1 END) c, SUM(this_issue_money) d, SUM(CASE WHEN is_not_exit = true AND enterprise_type_id = 1 THEN 1 END) e, SUM(CASE WHEN enterprise_type_id = 1 THEN this_issue_money END) f, SUM(CASE WHEN is_not_exit = true AND enterprise_type_id = 2 THEN 1 END) g, SUM(CASE WHEN enterprise_type_id = 2 THEN this_issue_money END) h, SUM(CASE WHEN is_not_exit = true AND enterprise_type_id = 2 THEN 1 END) i, SUM(CASE WHEN enterprise_type_id = 2 THEN this_issue_money END) j FROM k