首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Informix >

count(case when.distinct 解决方法

2012-02-27 
count(case when..distinct 解决办法SQL codeselect u,count(case when a is not null then distinct a el

count(case when..distinct 解决办法

SQL code
select u,count(case when a is not null then distinct a else b end)from t1group by 1

形如这样的代码出错,有什么解决办法吗?

现有的代码为
SQL code
select u.count(distinct a)from t1where a is not nullgroup by 1union allselect u.count(b)from t1where a is nullgroup by 1

觉得这样的代码实在太长,应该可以合并

[解决办法]
select U,count(*) from (
select U,case when a is null then a else b end as Na from t1 group by 1,2) a1
group by 1

热点排行