日期:2014-05-17 浏览次数:20759 次
CREATE TABLE t ( [status] int, s int ) go insert into t ([status],s) values (1000,5000) insert into t ([status],s) values (1001,100) insert into t ([status],s) values (1011,200) insert into t ([status],s) values (1003,300) insert into t ([status],s) values (3000,400) select 'total',s from t where [status] = 1000 UNION ALL select 'unsure',s from t where [status] = 1001 UNION ALL select 'sure',s as sure from t where [status] = 1011 UNION ALL select 'timeout',s as [timeout] from t where [status] = 1003 UNION ALL select 'reach',s as reach from t where [status] = 3000 total 5000 unsure 100 sure 200 timeout 300 reach 400
------解决方案--------------------
select COUNT(1) as total,status from table group by status
------解决方案--------------------
total,unsure,sure,timeout,reach的数量可以通过集计group by来取,取出各status的总数量分别对应一条数据,还要取其他字段的数据的话,其他字段数据可能不同,就要明确取哪一行数据才行