当前位置: 代码迷 >> Informix >> count(case when.distinct 解决方法
  详细解决方案

count(case when.distinct 解决方法

热度:9265   发布时间:2013-02-26 00:00:00.0
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
  相关解决方案