sql - COUNT within a WHERE clause or HAVING? -
this trying achieve;
select count(distinct no) table (type = 1 , count(distinct no) > num) or (type = 2 , count(distinct no) > num) group week what best way achieve this?
thanks
any aggregate comparisons need go having clause after group by. remember may different results depending on put non-aggregate conditional, because you'll aggregating on you've included/excluded via where.
ie
select count(distinct no) table type = 1 group week having count(distinct no) > num may different from
select count(distinct no) table group week having count(distinct no) > num , type = 1
Comments
Post a Comment