现有表TBA如下,ZA只能输1或不输,ZB只能输2或不输.........ZE只能输5或不输id ZA ZB ZC ZD ZE
1 1 2 5
2 2 4 5
3 1 3 4
4 2 3 3
5 2 4 5
要统计各个数字出现的次数select count(za),count(zb),count(zc),count(zd),count(ze) from TBA group by za,zb,zc,zd,ze以上写法怎么不正确?
1 1 2 5
2 2 4 5
3 1 3 4
4 2 3 3
5 2 4 5
要统计各个数字出现的次数select count(za),count(zb),count(zc),count(zd),count(ze) from TBA group by za,zb,zc,zd,ze以上写法怎么不正确?
解决方案 »
- 存储过程不能成功
- 这样的SQL语法写的很烂,大家看看怎么写漂亮一点
- 怎么改日期格式?
- 有没有谁知道写一个规则让分布试的SQL像在一台服务器上一样调用.
- 用mssql导出数据到不同库中的表自增ID无法自增的问题!!
- 急,误删数据库中的sysusers表中的dbo这条数据
- 急问:Sql Server的View中不支持Union,我该怎么办?
- 高分求助,在线等待一个trigger 触发过程的编辑
- 一个问题,请帮忙回答(100分)
- 快救命啊高手们、菜鸟兄弟们,偶遇到sql语句问题啦,怎么对数据库插入数据啊100分给你
- SQL Server 2005数据库远程登陆的问题,高手请进,帮帮小弟
- 救助!!!一个比较麻烦的查询
sum(case when zb=2 then 1 else 0 end)zb次數,
sum(case when zc=3 then 1 else 0 end)zc次數,
sum(case when zd=4 then 1 else 0 end)zd次數,
sum(case when za=5 then 1 else 0 end)ze次數
from tba
insert into tb values (null,null,null,null,null)
insert into tb values (null,2,null,4,5)
insert into tb values (1,null,3,4,null)
insert into tb values (null,2,3,null,5)
insert into tb values (1,2,null,null,5)
select count(a),count(b),count(c),count(d),count(e) from TB 如果你说的不输是"NULL" 那就这样即可
select a.count1,b.count2,c.count3,d.count4,e.count5 from
(
select count(id1) as count1,1as id from t7 where id1=1
) a
left join
(
select count(id2) as count2,1as id from t7 where id2=2
) b
on a.id=b.id
left join
(
select count(id3) as count3,1as id from t7 where id3=3
) c
on c.id=a.id
left join
(
select count(id4) as count4,1as id from t7 where id4=4
) d
on d.id=a.id
left join
(
select count(id5) as count5,1as id from t7 where id5=5
) e
on e.id=a.id
(
select count(convert(int,id1))as l1 ,count(convert(int,id2)) as l2,count(convert(int,id3)) as l3,
count(convert(int,id4)) as l4,count(convert(int,id5)) as l5
from t7
where id1=1 or id2=2 or id3=3 or id4=4 or id5=5
group by id1,id2,id3,id4,id5
) tt这是个用group by + Count的方法, 也够傻的了,还是用1楼的吧