今天数据库一条查询语句很慢,如下
select a.fld1,sum(b.fld2),b.fld3 from table1 a left join table2 b on a.fld1=b.fld1 where 条件 group by a.fld1,b.fld3
测试得到,若不进行汇总,速度很快,但一旦加入汇总,则非常慢,修改如下:
select a.fld1,b.fld2,b.fld3 into #t1 from table1 a left join table2 b on a.fld1=b.fld1 where 条件
select fld1,sum(fld2),fld3 from #t1 group by a.fld1,b.fld3
修改后速度非常快!