1
Rush9999 2019-01-23 15:27:01 +08:00
SELECT
businessNo, serviceType, SUM(s.num), SUM( CASE WHEN s.stauts = '2' THEN s.num END ), SUM( CASE WHEN s.stauts = '3' THEN s.num END ) FROM ( SELECT t.business_no AS businessNo, t.service_type AS serviceType, t.batch_status AS stauts, COUNT(t.datagram_id) AS num, updated_date AS date FROM t_issue_plat_datagram t GROUP BY t.business_no, t.batch_status ) s GROUP BY s.businessNo ORDER BY s.date |
3
lxy42 2019-01-23 16:33:04 +08:00
SELECT
business_no, service_type, COUNT(1) as limitCount, COUNT(CASE WHEN batch_status = '2' THEN 1 ELSE 0 END) as successCount, COUNT(CASE WHEN batch_status = '3' THEN 1 ELSE 0 END) as falseCount, FROM t_issue_plat_datagram GROUP BY business_no ORDER BY updated_date 楼主试试这个,不知道是否符合查询需求 |
4
nulihuxi OP @lxy42 感谢回复!查询出的条数是对的,不过 limitCount、successCount、falseCount 的值是一样的
|
5
lxy42 2019-01-23 16:59:35 +08:00
SELECT
business_no, service_type, COUNT(1) as limitCount, COUNT(CASE WHEN batch_status = '2' THEN 1 ELSE NULL END) as successCount, COUNT(CASE WHEN batch_status = '3' THEN 1 ELSE NULL END) as falseCount, FROM t_issue_plat_datagram GROUP BY business_no ORDER BY updated_date 这个呢?小改了一下。 |