日期:2014-05-17  浏览次数:20701 次

SQL高手进来,跪求一条SQL语句
表A中有一个字段status,其他字段省略..
1000:全部订单
1001:待确认
1011:已预订
1003:已超时
3000:已到店


需要根据不同的status进行查询,返回结果如下
total 全部订单数量
unsure 待确认订单数量
sure 已预订订单数量
timeout 已超时订单数量
reach 已到店订单数量
以及表中所有的字段

这个SQL语句要怎么实现啊,求各位大神赐教。。

------解决方案--------------------
select COUNT(status) as statecount,status from wds_a_sellinfor group by status
------解决方案--------------------
SELECT total,unsure,sure,timeout,reach FROM A WHERE status=''


------解决方案--------------------
SQL code

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的总数量分别对应一条数据,还要取其他字段的数据的话,其他字段数据可能不同,就要明确取哪一行数据才行