首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求优化这条SQL语句,该如何处理

2012-03-09 
求优化这条SQL语句RTSQL codeselect ct.ct_id,sc.scid,tea_name,cau_name,ct_time from SetCause as sc,Ca

求优化这条SQL语句
RT

SQL code
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+'%'

可以拆分,越效率越好

[解决办法]
好麻煩,最好建立索引,SQL中Exists好像不能用吧
[解决办法]
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 ,
(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
------------------------------

热点排行