求助这个sql还能怎么优化

w1005410186 2015-12-25 07:06:51
select count(distinct (a.customerno)) from lcaccount a
where a.customerno in (select b.appntno from lccont b,lcpol c where b.contno=c.contno and c.appflag='1')
or a.customerno in (select c.insuredno from lccont b,lcpol c where b.contno=c.contno and c.appflag='1');
...全文
113 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
等不到来世 2015-12-28
  • 打赏
  • 举报
回复
引用 3 楼 yupeigu 的回复:
[quote=引用 2 楼 szx1999 的回复:]

--这个count跟lcaccount表其实没有半毛钱关系
select COUNT(appntno) from(
select b.appntno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
union
select  c.insuredno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
) t
从逻辑上来说,其实还是有关系的,如果子查询中的appntno去重后,要比lcaccount里的 appntno要多,那么就会有问题。[/quote] 嗯,是我想错了。
LongRui888 2015-12-28
  • 打赏
  • 举报
回复
引用 2 楼 szx1999 的回复:

--这个count跟lcaccount表其实没有半毛钱关系
select COUNT(appntno) from(
select b.appntno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
union
select  c.insuredno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
) t
从逻辑上来说,其实还是有关系的,如果子查询中的appntno去重后,要比lcaccount里的 appntno要多,那么就会有问题。
等不到来世 2015-12-26
  • 打赏
  • 举报
回复

--这个count跟lcaccount表其实没有半毛钱关系
select COUNT(appntno) from(
select b.appntno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
union
select  c.insuredno  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1'
) t
中国风 2015-12-25
  • 打赏
  • 举报
回复

select   count(distinct (a.customerno)) 
from lcaccount a
where exists(select 1  from lccont b,lcpol c where b.contno=c.contno and c.appflag='1' and a.customerno  in(b.appntno,c.insuredno))

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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