帮忙优化下

liyufu86 2009-04-10 05:12:23
前人写的代码
发现执行起来很慢

高人看看怎么优化

select count( distinct a.id ) from OrderProductItem a where ( a.stauts= 2 and a.orgId= 10000 ) or (a.id in (select a.parentid from a where a.stauts= 0 and a.stauts_deliver= 22 group by a.parentid ))

十分感谢

不知道为什么很慢,
...全文
95 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
you_tube 2009-04-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liyufu86 的回复:]
谢谢楼上的2位,为什么我的那个查询很慢呢
[/Quote]


select count( distinct a.id ) from OrderProductItem a where ( a.stauts= 2 and a.orgId= 10000 ) or (a.id in (select a.parentid from a where a.stauts= 0 and a.stauts_deliver= 22 group by a.parentid ))

in这个相当再查询一遍



等不到来世 2009-04-10
  • 打赏
  • 举报
回复
你那个查询应该会运行时报错。
等不到来世 2009-04-10
  • 打赏
  • 举报
回复
select count(distinct id)
from
(
select id from OrderProductItem where stauts= 2 and orgId= 10000
union all
select a.id
from OrderProductItem a join OrderProductItem b
on a.id=b.parentid
where b.stauts=0 and b.stauts_deliver= 22
) t
liyufu86 2009-04-10
  • 打赏
  • 举报
回复
谢谢楼上的2位,为什么我的那个查询很慢呢
moonshineidolon 2009-04-10
  • 打赏
  • 举报
回复
select count( distinct a.id )

from OrderProductItem a where

( a.stauts= 2 and a.orgId= 10000 ) or

(

a.id in (


select a.parentid from a where a.stauts= 0 and a.stauts_deliver= 22


)

)
pt1314917 2009-04-10
  • 打赏
  • 举报
回复

--try:
select count( distinct a.id ) from OrderProductItem a ,a t
where (a.stauts= 2 and a.orgId= 10000 ) or (a.id=t.parentid and t.stauts= 0 and t.stauts_deliver= 22 )

22,219

社区成员

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

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