SQL奇怪问题,某段数据Select比别的数据段速度慢!!
有相关表和字段
表A S_NO
表B S_NO、P_NO
表C P_NO、P_Date
里面有1~11月的相关数据
使用
select * from A表 where S_NO in(select S_NO from B表 where P_NO in (select P_NO from C表 where P_date between '2006-01-01' and '2006-11-30'))
这一个SQL语句得到结果的时间要比
select * from A表 where S_NO in(select S_NO from B表 where P_NO in (select P_NO from C表 where P_date between '2006-11-01' and '2006-11-30'))
这句得到结果的时间短得多.
不明白怎么回事
请各位指教一下.
有相关表和字段
表A S_NO
表B S_NO、P_NO
表C P_NO、P_Date
里面有1~11月的相关数据
使用
select * from A表 where S_NO in(select S_NO from B表 where P_NO in (select P_NO from C表 where P_date between '2006-01-01' and '2006-11-30'))
这一个SQL语句得到结果的时间要比
select * from A表 where S_NO in(select S_NO from B表 where P_NO in (select P_NO from C表 where P_date between '2006-11-01' and '2006-11-30'))
这句得到结果的时间短得多.
不明白怎么回事
请各位指教一下.
解决方案 »
- ms sql server2005怎么做可以记录下来 "没有足够的系统内存来运行此查询" 的查询语句?
- 查詢數據的速度很快,但是將這些數據插入到一個表速度則相當慢?請教高手!
- update top 2 ....怎么随机更新符合条件 中的2条
- 用PB+mssql 2000开发软件客户端不安装mssql,需要安哪些文件
- update语句中的使用了链接服务器,为什么执行非常慢,有什么方法可以改进?
- 急急急!!!!!帮我解决多少分都行!!速度
- 应该是很简单的问题,大家请进
- 如何备份事务日志
- 一打开sql2000 的全文检索(mssearch)服务,cpu 占用率就达到了90%多(没有进行任何操作)。
- sql根据某一个字段重复只取第一条数据,并且是取整条数据
- 紧急求助~~~~~~~~ 速度!!!!!!!!!
- INT型的变量如何用SELECT 语句进行数据库操作
select * from A表 as a where exists
(select * from B表 b inner Join C表 as c on b.P_NO=c.P_NO
where c.P_date between '2006-01-01' and '2006-11-30' and a.S_NO=b.S_NO)
用between时,最好加小时段'2006-11-30 23:59:59'
'2006-11-30'等于'2006-11-30 00:00:00'
select * from A表 where exists
(select 1 from B表 where S_NO=A表.S_NO and exists
(select 1 from C表 where P_NO=B表.P_NO and P_date between '2006-01-01' and '2006-11-30'))
楼主可以测试一下速度
只是时间段不同
只有11月份的数据Select的时候速度慢
其他月份不会慢
奇怪的情况是
1.如果Between '2006-10-01' and '2006-11-30'的话
速度就很快了.时间花不了1秒.
2.如果是 Between '2006-11-01' and '2006-11-30'的话,
速度变慢.时间要花22秒
3.如果把C表11月的数据改为12月或别的月.速度变快.时间花不了1秒
先
Update C set P_Date=P_Date+30 where P_Date Between '2006-11-01' and '2006-11-30'
再
select * from A表 where S_NO in(select S_NO from B表 where P_NO in (select P_NO from C表 where P_date between '2006-12-01' and '2006-12-30'))
WangZWang(先来)
的方法
是快很多但
我想知道
我这个问题是什么搞出来的?
很明显
1~11月的数据
总要比单独11月的数据多吧
怎么会Select 1~11的速度要比 Select 11 的速度快呢?