One SQL statement for statistics query bitsCN.com
One SQL statement for statistical query
When programmers make the following statistics, they now provide two implementation solutions:
Solution 1: Use SEKECT CASE WHEN
Explain select count (*) AS 'total', count (CASE oup. status WHEN '1' THEN oup. id END) AS 'unbound ', count (CASE oup. status WHEN '2' THEN oup. id END) AS 'bound', count (CASE oup. status WHEN '3' THEN oup. id END) AS 'freeze 'FROM lab_org_uc_passport oup
Display result: (display by row)
Solution 2:
SELECT count (*) AS 'Total' FROM lab_org_uc_passport oup union all select count (*) AS 'not bound' FROM lab_org_uc_passport oup WHERE oup. status = '1' union all select count (*) AS 'not bound' FROM lab_org_uc_passport oup WHERE oup. status = '2' union all select count (*) AS 'not bound' FROM lab_org_uc_passport oup WHERE oup. status = '3'
Display result (by column)
34
3
10
21
BitsCN.com