请问这个SQL语句怎么优化

z523714705 2014-06-17 12:45:57
select time,week,az,xz,op from (  

select b.time as time ,b.week as week,
SUM(case b.status when 'az' then b.counts else 0 end ) as 'az',
SUM(case b.status when 'xz' then b.counts else 0 end ) as 'xz',
SUM(case b.status when 'open' then b.counts else 0 end ) as 'op' from (

select status,time,week,COUNT(status) as counts from (


select distinct status,time,week,ip from kp_statistics where
TO_DAYS(NOW()) - TO_DAYS(time) <= 50 and time!='2014-06-16' and
(status = 'az' or status = 'xz' or status = 'open') group by status,time,week,ip

) a group by status,time ,week

) b group by b.time ,b.week order by time desc

)t where TO_DAYS(NOW()) - TO_DAYS(time) <= 50 and time!='2014-06-16' limit 0,30
...全文
96 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
缘与我无缘 2014-06-17
  • 打赏
  • 举报
回复
建议你看看这里 http://blog.csdn.net/csh624366188/article/details/8457749 你内部sql语句已经进行过滤,外部又加条件,是否重复?

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧