设表有十个字段,
如何查询
任意两个字段及以上不为空的记录?
如何查询
任意两个字段及以上不为空的记录?
解决方案 »
- 这样查询,为什么查询的结果正确,但是没一项都是testbaseinfo中记录的倍数,如查询出A,则显示有n个A
- 创建视图的问题~! 不好意思没有分了
- 求今天是一年当中的第几天和当年有多少天?
- 怎样从SQL SERVER中的某一个数据库中提取所有表名?
- 关于更新数据中一个非常奇怪的问题。
- 删除日志出错?
- 我合并两条查询语句,为什么查询了好几分钟都查不出来,分别执行都可以查询处来。请高手进来看看80分送上,解决立马送分!!谢谢!!!!
- 大字段问题,急...............
- 有关关系表的sql
- 数据库的字段很大对数据库的效率有什么影响?
- 【提问】请教一sql
- 查询结果数据表 添加返回条数 急 高手出招!!!!
(case when c1 is not null then 1 else 0 end) +
(case when c2 is not null then 1 else 0 end) +
(case when c3 is not null then 1 else 0 end) +
(case when c4 is not null then 1 else 0 end) +
(case when c5 is not null then 1 else 0 end) +
(case when c6 is not null then 1 else 0 end) +
(case when c7 is not null then 1 else 0 end) +
(case when c8 is not null then 1 else 0 end) +
(case when c9 is not null then 1 else 0 end) +
(case when c10 is not null then 1 else 0 end) >= 2
from syscolumns where id=object_id('tb')select @sql ='select * from tb where (case isnull('+@sql+'>=2'exec(@sql)
select id = row_number() over (order by col1),
num = isnull(nullif(isnull(col1 , 1),col1),1)+ isnull(nullif(isnull(col2 , 1),col2),1)...
)select * from cte where num>2
也可以用case when哦, 理解错了, 我是找的null >2
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+'+(case isnull('+ name +','''') when '''' then 0 else 1 end)'
from syscolumns where id=object_id('tb')
set @sql='select * from tb where '+ stuff(@sql,1,1,'') +'>2'
exec(@sql)