select sum(case when 项1字段 is not null then 1 else 0 end),
sum(case when 项2字段 is not null then 1 else 0 end),
...
sum(case when 项26字段 is not null then 1 else 0 end)
from t
sum(case when 项2字段 is not null then 1 else 0 end),
...
sum(case when 项26字段 is not null then 1 else 0 end)
from t
解决方案 »
- com.microsoft.sqlserver.jdbc.SQLServerException异常
- 我的表设计成这样的,根据日期段来查询.怎么解决?高手指点!!!
- 关于统计个数的问题
- 想修改SQL Server 的SA密码,对其他的SQL Server object会有影响吗?
- 【帮人提问!!!Windows 2000 pro 能不能安装SQL 2000 server呀?】
- 新手求救,xp下为何装不了sql 2000
- mssql里的一个表不能删除,求救?
- 把SQL SERVER的存储过程放在文本文件里,JAVA读取这个文件执行报错
- 请教各位专家:70GB的数据库500个分区表,怎样提高查询速度
- 询复杂sql语句(急)
- 数据表格式转换(因上一贴写错了需求结帖重开一帖)
- 如何将字符切成几个
insert test select null,'a'
union all select 'b','c'select total=col1+col2,col1,col2 from
(
select col1=sum(case when col1 is not null then 1 else 0 end),
col2=sum(case when col2 is not null then 1 else 0 end)
from test
)adrop table testtotal col1 col2
----------- ----------- -----------
3 1 2
WHEN CEO IS NOT NULL THEN 1
WHEN CEO <> '' THEN 1
ELSE 0
END)
FROM tSELECT COUNT(*) FROM t
WHERE CEO IS NOT NULL AND CEO <> ''两条语句出的结果不一样
WHEN CEO IS NOT NULL and CEO<>'' THEN 1
ELSE 0
END)
FROM t
按指定顺序为每个 WHEN 子句的 Boolean_expression 求值。
返回第一个取值为 TRUE 的 Boolean_expression 的 result_expression。
如果没有取值为 TRUE 的 Boolean_expression,则当指定 ELSE 子句时 SQL Server 将返回 else_result_expression;若没有指定 ELSE 子句,则返回 NULL 值。 照你的写法,''非空,当然会返回1了,根本不会进行<>''的判断,结果怎么可能对。