1
SELECT app, result, COUNT(*) AS cnt 
FROM table
GROUP BY app, result 

下一个返回我:

app|result|cnt|
ap1|FAIL  |111|
ap1|PASS  |99 |
ap2|FAIL  |222|
ap3|PASS  |333|

但我需要这样:

app|cnt_FAIL|cnt_PASS|

ap1|111     |99      |  
ap2|222     |0       |
ap3|0       |333     |
4

1 回答 1

1

试试这个方法:

SELECT app, 
       SUM (case when result = 'PASS' then 1 else 0 end ) cnt_pass,
       SUM (case when result = 'FAIL' then 1 else 0 end ) cnt_fail
FROM table
GROUP BY app
于 2013-08-04T01:14:12.397 回答