统计问题
表:
id CustomerID
1 1232132
2 4324324
3 3243153
1 3243424
2 4431431
3 NULL
4 NULL
如何得到以下结果:
id CustomerNum
1 2
2 2
3 1
4 0
问题点数:20、回复次数:9Top
1 楼vinsonshen(为了明天)回复于 2005-01-04 10:58:59 得分 0
我好好的学习Top
2 楼lsxaa(小李铅笔刀)回复于 2005-01-04 11:00:46 得分 20
selec id,sum(case when customerid is null then 0 else 1 end) as CustomerNum
from 表
gorup by id
order by idTop
3 楼NICOJOHN(鱼儿习惯潜水)回复于 2005-01-04 11:02:45 得分 0
selec id,customernum=sum(case when customerid is null then 0 else 1 end)
from 表
gorup by idTop
4 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-01-04 11:03:18 得分 0
刀哥的可以..
Top
5 楼hjqnet(菜菜菜鸟)回复于 2005-01-04 11:07:50 得分 0
gorup?
晕~~~~~~~
在关键字 'CASE' 附近有语法错误。Top
6 楼long0104()回复于 2005-01-04 11:08:23 得分 0
selec id,sum(case when customerid is null then 0 else 1 end) as CustomerNum
from 表
gorup by id
order by id
Top
7 楼hjqnet(菜菜菜鸟)回复于 2005-01-04 11:08:49 得分 0
selecTop
8 楼lsxaa(小李铅笔刀)回复于 2005-01-04 11:11:58 得分 0
呵呵 本来是完整的,发上来半路被人给贪污了一个字母 tTop
9 楼accumpzhu(夜色心情)回复于 2005-01-04 11:38:12 得分 0
select id,sum(case when customerid is null then 0 else 1 end) as CustomerNum
from 表
gorup by id
order by idTop




