SQL语句优化求助 - MS-SQL Server / 疑难问题
我这有一段语句:
select a.aaid,amount,b.exit_amount
from (select id,object_id,amount,price,date1 from AA where date1 BETWEEN '20100401' AND '20100430' ) a
LEFT JOIN
(SELECT aa_id, isnull(SUM(exit_amount), 0) AS exit_amount from AA_Exit GROUP BY aa_id) b ON a.id = b.yz_id
现在有个问题:
AA这个表有40万条数据,现在我用左连接,语句如上,这样执行要15秒时间.但如果改成如下语句,就只要1秒钟.
select a.aaid,amount
from (select id,object_id,amount,price,date1 from AA where date1 BETWEEN '20100401' AND '20100430' ) a
LEFT JOIN
(SELECT aa_id, isnull(SUM(exit_amount), 0) AS exit_amount from AA_Exit GROUP BY aa_id) b ON a.id = b.yz_id
但我现在必须要用上面这条语句执行.该如何优化.
一样?》
create index ix_aa_id on AA_Exit(aa_id)建索引 试一下
第二次1秒是因为直接从BUFFER CACHE取的原因吧,没有理由两个相差这么大.
{{
相关问答:
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
请问
添加新数据源->数据库->添加连接
这个界面下,数据源选择:Microsoft SQL Server (SqlClient);
服务器名:
应该写什么呢?
有谁知道?多谢各位!!
你到底是要连mysql还是mssql?
引用
请问
......
请教高手:
以下是数据库中的三条记录,英文为字段名称
id planname TaskBeginTime Status
329 2010年03 ......