SQL高手进来,跪求一条SQL语句

JoesenZhao 2012-10-19 10:49:07
表A中有一个字段status,其他字段省略..
1000:全部订单
1001:待确认
1011:已预订
1003:已超时
3000:已到店


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

这个SQL语句要怎么实现啊,求各位大神赐教。。
...全文
184 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
stiff_neck 2012-10-19
  • 打赏
  • 举报
回复
total,unsure,sure,timeout,reach的数量可以通过集计group by来取,取出各status的总数量分别对应一条数据,还要取其他字段的数据的话,其他字段数据可能不同,就要明确取哪一行数据才行
wangyizhi58 2012-10-19
  • 打赏
  • 举报
回复
select COUNT(1) as total,status from table group by status
andy_wanhl 2012-10-19
  • 打赏
  • 举报
回复

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 total,unsure,sure,timeout,reach FROM A WHERE status=''

风之影子 2012-10-19
  • 打赏
  • 举报
回复
select COUNT(status) as statecount,status from wds_a_sellinfor group by status

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧