sybase数据库中如何查出空值的统计数
举例说明:A表有字段如下:姓名,文化程度(xm,whcd)。
内容为:张三 大学
李四 高中
AB 高中
AC 高中
BA
BC
BD
SQL语句为 select whcd,count(whcd) as 'sum' from A group by whcd
结果为: 大学 1
高中 3
0
查到的空值为0 ,可实际上空值是3个
用 select count(*) from A where whcd = '' or whcd is null 查到的总数也是3。
请教诸位,select whcd,count(whcd) as 'sum' from A group by whcd ,这条sql语句怎么改,才能把空值统计出来?
问题点数:100、回复次数:7Top
1 楼zhangdatou(猪头)回复于 2005-01-07 12:14:01 得分 0
SELECT NVL(WHCD, '其它'), COUNT(NVL(WHCD, '其它')) AS 'SUM' FROM A GROUP BY WHCDTop
2 楼curmudgeon(nicolas)回复于 2005-01-07 12:14:06 得分 0
补充:select count(*) from A where whcd = '' or whcd is null 查到的总数是3
但 select count(whcd) from A where whcd = '' or whcd is null 查到的总数是0Top
3 楼lzp_lrp(lzp)回复于 2005-01-07 12:18:31 得分 0
SELECT NVL(WHCD, ' '), SUM(1) AS 'SUM' FROM A GROUP BY WHCD
或者
SELECT NVL(WHCD, ' '), Count(1) AS 'SUM' FROM A GROUP BY WHCD
Top
4 楼hygougou(uoguogyh)回复于 2005-01-07 12:19:20 得分 100
select whcd,count(isnull(whcd,'')) as 'sum' from A group by whcdTop
5 楼curmudgeon(nicolas)回复于 2005-01-07 12:21:43 得分 0
一楼:是sybase数据库,没有NVL吧Top
6 楼curmudgeon(nicolas)回复于 2005-01-07 12:35:07 得分 0
hygougou(狗狗) 说的办法行,不过再请问,如果生成select whcd,count(isnull(whcd,'')) as 'sum' from A group by whcd 的时候并不知道WHCD是字符型还是数字型的,那样的话,isnull怎么写,用CASE吗?能否给出具体代码?THANK YOU。
Top
7 楼curmudgeon(nicolas)回复于 2005-01-07 12:36:04 得分 0
自己顶!!!Top





