求一条SQL语句的优化
SQL语句如下,有什么办法效率可以高一点?BillFlow表记录数在20万条以上,UserInfo表记录数在5万条左右
Update tmpRep_Area Set AreaBilled=IsNull(a.AreaBilled,0),AreaNoBill=IsNull(c.AreaNoBill,0),AreaIsCardBilled=d.AreaIsCardBilled,AreaNoCardBilled=e.AreaNoCardBilled
From tmpRep_Area a,
(Select Bill.AreaCode,Count(Bill.AddrCode) As AreaBilled
From (Select b.AreaCode,a.AddrCode From BillFlow a
Left Join UserInfo b On b.AddrCode=a.AddrCode
Left Join AreaInfo c On c.AreaCode=b.AreaCode
Where Convert(Char(6),BillDate,112)=@RepDate
And DataFlag=0 And b.UserStatus<>'封表' And b.UserStatus<>'注销'
And a.ID Not In(Select BillFlowID From BillFlowCancel Where Convert(Char(6),CancelDate,112)=@RepDate)
Group By b.AreaCode,a.AddrCode) Bill
Group By Bill.AreaCode) b,
(Select AreaCode,Count(AddrCode) As AreaNoBill From UserInfo
Where UserStatus<>'封表' And UserStatus<>'注销'
And Convert(Char(6),CreatDate,112)<=@RepDate
And AddrCode
Not In (Select AddrCode From BillFlow
Where Convert(Char(6),BillDate,112)=@RepDate
And DataFlag=0
And id Not In(Select BillFlowID From BillFlowCancel
Where Convert(Char(6),CancelDate,112)=@RepDate))
Group By AreaCode) c,
(Select AreaCode,Count(AddrCode) As AreaIsCardBilled From UserInfo
Where UserStatus<>'封表' And UserStatus<>'注销'
And Convert(Char(6),CardCreatDate,112)<=@RepDate
And IsUseCard=1 And AddrCode
In (Select AddrCode From BillFlow
Where Convert(Char(6),BillDate,112)=@RepDate
And DataFlag=0
And id Not In(Select BillFlowID From BillFlowCancel
Where Convert(Char(6),CancelDate,112)=@RepDate))
Group By AreaCode) d,
(Select AreaCode,Count(AddrCode) As AreaNoCardBilled From UserInfo
Where UserStatus<>'封表' And UserStatus<>'注销'
And Convert(Char(6),CreatDate,112)<=@RepDate
And (IsUseCard=0 Or IsUseCard=1 And Convert(Char(6),CardCreatDate,112)>=@RepDate)
And AddrCode
In (Select AddrCode From BillFlow
Where Convert(Char(6),BillDate,112)=@RepDate
And DataFlag=0
And id Not In(Select BillFlowID From BillFlowCancel
Where Convert(Char(6),CancelDate,112)=@RepDate))
Group By AreaCode) e
Where a.AreaCode=b.AreaCode And c.AreaCode=a.AreaCode And a.AreaCode=d.AreaCode And a.AreaCode=e.AreaCode
...全文
相关推荐
Mysql查询最近一条记录的sql语句(优化篇)
主要介绍了Mysql查询最近一条记录的sql语句,非常不错,具有一定的参考借鉴价值,需要的朋友参考下吧
一条SQL引发的“血案”:与SQL优化相关的个案例(文末送书).docx
一条SQL引发的“血案”:与SQL优化相关的个案例(文末送书).docx
oracle下一条SQL语句的优化过程(比较详细)
很简单的一次调整,语句加了适当的索引后性能就有大幅的提升。当时看到这条语句的时候,第一感觉就是执行效率肯定低下。语句的功能是求某一客户当天产品的总销量。
一条SQL引发的“血案”:与SQL优化相关的4个案例.docx
一条SQL引发的“血案”:与SQL优化相关的4个案例.docx
优化一条千万级别数据的SQL语句
一张千万级别user表,涉及到的列id, name, sexcreate_time,id为主键。当前sql如下: select * from user where create_time between '2020-01-01' and '2023-0101' limit 5000000,100 是否存在优化空间?


