select       
User.ID as UserID,
case count(distinct 
case
when Amount>0 or Fee>0 then userid
else null
end
)
 when 0 then 0
 else 1
 end ,
 case count( distinct 
case IsEnabled
when 1 then userid
else null
end) 
  when 0 then 0 
  else 1
  end   ,
                  accontID  from  a.......这里
case count(distinct 
case
when Amount>0 or Fee>0 then userid
else null
end
)
 when 0 then 0
 else 1
 end ,
 case count( distinct 
case IsEnabled
when 1 then userid
else null
end) 
  when 0 then 0 
  else 1
  end    是什么意思 ??

解决方案 »

  1.   

    V1:Amount>0 or Fee>0 的不重复 userid 数
    V1=0 ? 0 : 1V2: IsEnabled=1 的不重复 userid 数
    V2=0 ? 0 : 1
      

  2.   

    这个逻辑又为何要distinct呢?
      

  3.   

    简化sign(count(case when Amount>0 or Fee>0 then userid end)),
    sign(count(case IsEnabled when 1 then userid end))
      

  4.   

    选择一个
    case count(distinct case when Amount>0 or Fee>0 then userid else null end )
    when 0 then 0
    else 1
    end ,这样明白了点 应该是这个意思 case when Amount>0 or Fee>0  那个count(distinct userId)的数据 ,否则 count(distinct null)
    如果count(distinct结果为0--》 0
        count(distinct结果不为0   ---》 1
      

  5.   

    1:统计满足Amount>0 or Fee>0 条件不重复userid的个数,
    如果为0,没有此条件userid,则为0,如果有,则为12,采用case嵌套
    统计满足IsEnabled=1条件不重复userid的个数
    如果为0,没有此条件userid,则为0,如果有,则为1
      

  6.   

     select count(distinct null)
    ;
    +----------------------+
    | count(distinct null) |
    +----------------------+
    |                    0 |
    +----------------------+
    1 row in set-------------可行的