加索引:
create index idx_test on [table](A,B,C)我做了一个小测试,发现第二种方法比较快:set statistics time on
select fitemid,max(fqty) from icstockbillentry group by fitemid
set statistics time off
/*SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 1184 毫秒。(11268 行受影响)
*/set statistics time on
select fitemid,fqty from icstockbillentry t where not exists(select 1 from icstockbillentry where fitemid=t.fitemid and fqty>t.fqty)
set statistics time off
/*
SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。SQL Server 执行时间:
CPU 时间 = 13 毫秒,耗费时间 = 138 毫秒。(11268 行受影响)
*/
create index idx_test on [table](A,B,C)我做了一个小测试,发现第二种方法比较快:set statistics time on
select fitemid,max(fqty) from icstockbillentry group by fitemid
set statistics time off
/*SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 1184 毫秒。(11268 行受影响)
*/set statistics time on
select fitemid,fqty from icstockbillentry t where not exists(select 1 from icstockbillentry where fitemid=t.fitemid and fqty>t.fqty)
set statistics time off
/*
SQL Server 执行时间:
CPU 时间 = 0 毫秒,耗费时间 = 0 毫秒。SQL Server 执行时间:
CPU 时间 = 13 毫秒,耗费时间 = 138 毫秒。(11268 行受影响)
*/
解决方案 »
- win7系统无法安装sql server2005的问题
- mysql 它总是说access denied
- 求一查询语句,数据值作为列
- 去重复,并显示本来就不重复的记录
- ◆◇◆ Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired. ◆◇◆
- SqlServer中如何根据列的不同值去取不同表的列
- 对于淘宝网中好评率的设计
- 一个关于锁的问题,请邹健,大力以及其他朋友帮看看
- sql server 存储过程里我无法通过asp获得记录集(select from 一张临时表)
- sqlserver数据库表存储顺序
- SQL 数据库的数据老是丢失
- 关键字 'select' 附近有语法错误,局部变量,全局变量
第1个,a,b,max(c), 相同的a,b只会有1条
第2个,当c最大有几条时,就会出来几条
另外:楼主可以自己测试一下,看看每个语句的执行所需要的时间。
方法:
declare @t datetime
set @t=getdate()
执行你的语句
select 执行时间=datediff(mm,@t,getdate())这样就可以比较出来了