谁帮改改SQL语句,让更快执行

liumang9527 2007-09-14 12:35:14
select ENTERPRISE_NUM ,
SUM(CASE WHEN status = 'A' then 1 else 0 end) ,
SUM(CASE WHEN status = 'Z' then 1 else 0 end)
from virtel_telrecord
where start_time>= '2006-8-2 10:35:12'
and sn not in
(select b.sn from virtel_telrecord b ,virtel_telrecord c
where b.source = c.source and b.dest = c.dest
and b.sn !=c.sn and b.status = 'Z'
and c.end_time = b.start_time)
group by ENTERPRISE_NUM

帮帮忙
...全文
94 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Limpire 2007-09-14
  • 打赏
  • 举报
回复
-- try

select a.ENTERPRISE_NUM ,
SUM(CASE WHEN a.status = 'A' then 1 else 0 end) ,
SUM(CASE WHEN a.status = 'Z' then 1 else 0 end)
from
virtel_telrecord a
left join
(select b.sn from virtel_telrecord b ,virtel_telrecord c
where b.source = c.source and b.dest = c.dest
and b.sn !=c.sn and b.status = 'Z'
and c.end_time = b.start_time) b
on a.sn = b.sn
where a.start_time >= '2006-8-2 10:35:12' and b.sn is null
group by a.ENTERPRISE_NUM

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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