求优化这条SQL语句

weeksun23 2012-01-31 09:50:34
RT

select ct.ct_id,sc.scid,tea_name,cau_name,ct_time from SetCause as sc,CauseTime as ct,CauseInfo as ci,TeaAccount as ta where ct.scid = sc.scid and sc.cau_id = ci.cau_id and sc.tea_id = ta.tea_id and ci.cau_id not in (select ci.cau_id from SetCauseTime as sct,SetCause as sc,CauseTime as ct,CauseInfo as ci where sct.ct_id = ct.ct_id and ct.scid = sc.scid and sc.cau_id = ci.cau_id and sct.stu_id = @stu_id) and ci.cau_name like '%'+@causeValue+'%'

可以拆分,越效率越好
...全文
124 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-01-31
  • 打赏
  • 举报
回复
这么多表,视图处理
zhangweitc123 2012-01-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ju523756055 的回复:]
SQL code


视图 索引
[/Quote].
jmx123456789 2012-01-31
  • 打赏
  • 举报
回复

视图 索引
victor_yang 2012-01-31
  • 打赏
  • 举报
回复
出现了 not in 和 like 操作符,这些都是很慢的,要看看数据库结构才知道怎么优化。
紫竹林畔 2012-01-31
  • 打赏
  • 举报
回复
关键
and ci.cau_name like '%'+@causeValue+'%'
这里没什么可优化的
perisenjut 2012-01-31
  • 打赏
  • 举报
回复
对关键列聚集索引吧
mike 2012-01-31
  • 打赏
  • 举报
回复
好麻煩,最好建立索引,SQL中Exists好像不能用吧
sundayzhao 2012-01-31
  • 打赏
  • 举报
回复
太烦了,改为not Exists能快些
anny_gomine 2012-01-31
  • 打赏
  • 举报
回复
看了就头疼
weeksun23 2012-01-31
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 upcc 的回复:]
SQL code

select ct.ct_id,sc.scid,tea_name,cau_name,ct_time from
SetCause as sc,
CauseTime as ct,
(Select * From CauseInfo Where cau_name like '%'+@causeValue+'%')[ci],
TeaAccount as ta ,
(Sel……
[/Quote]
我测试过,与我原来的select结果不一样
weeksun23 2012-01-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ju523756055 的回复:]
SQL code

视图 索引
[/Quote]
不懂。。。
weeksun23 2012-01-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 perisenjut 的回复:]
对关键列聚集索引吧
[/Quote]
具体应该怎么做?
Dong 2012-01-31
  • 打赏
  • 举报
回复

select ct.ct_id,sc.scid,tea_name,cau_name,ct_time from
SetCause as sc,
CauseTime as ct,
(Select * From CauseInfo Where cau_name like '%'+@causeValue+'%')[ci],
TeaAccount as ta ,
(Select * From SetCauseTime Where stu_id <> @stu_id)[sct],
where
sct.ct_id = ct.ct_id and
ct.scid = sc.scid and
sc.cau_id = ci.cau_id and
sc.tea_id = ta.tea_id
Dong 2012-01-31
  • 打赏
  • 举报
回复
select ct.ct_id,sc.scid,tea_name,cau_name,ct_time from
SetCause as sc,
CauseTime as ct,
(Select * From CauseInfo Where cau_name like '%'+@causeValue+'%')[ci],
TeaAccount as ta ,
(Select * From SetCauseTime Where stu_id <> @stu_id)[sct]
where
sct.ct_id = ct.ct_id and
ct.scid = sc.scid and
sc.cau_id = ci.cau_id and
sc.tea_id = ta.tea_id
------------------------------

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧