有一条语句需要改写
select count(distinct(id)) , case when..... ---(条件相当多)
from table
...group by a.b在系统发现这个语句在高峰期间很很耗资源,但我开session是相当快。
思考半天只能 count(distinct(id) 将它改写 (近3个月的experience
知道有distinct就不是好事情,他会很慢)现在有意思将它替换,问有什么方便的方法?
(我的初步想法
select
group by having count(×) 》2
》
---可以实现distinct
但是我不知道count(distinct)如何用 group by实现
)??
select count(distinct(id)) , case when..... ---(条件相当多)
from table
...group by a.b在系统发现这个语句在高峰期间很很耗资源,但我开session是相当快。
思考半天只能 count(distinct(id) 将它改写 (近3个月的experience
知道有distinct就不是好事情,他会很慢)现在有意思将它替换,问有什么方便的方法?
(我的初步想法
select
group by having count(×) 》2
》
---可以实现distinct
但是我不知道count(distinct)如何用 group by实现
)??
select count(distinct(ul.Id)) number, CASE THEN 4 ELSE 5 END as Interval
from SessionLog ul,User u where u.id = ul.id group by Interval;请注意group by的字段和count(distinct(ul.Id)) 中的字段是不同的哦啦