首页新闻找找看学习计划

SQL 优化

0
悬赏园豆:5 [待解决问题]

例如,像这样的查询:SELECT
w.Id,
w.JJ_Consignment,
w.JU_PK,
(SELECT Top 1 JS_Lead FROM #TMP_SHIP s WHERE s.JS_Lead=w.JS_Ship) As JS_Lead,
w.JS_Ship,

(SELECT Top 1 JK_Consol FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship) As JK_Consol,
(SELECT Top 1 JV_Vessel FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship) As JV_Vessel,
(SELECT Top 1 JV_voyage FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship) As JV_voyage,

w.JU_Planned,

w.JU_ActualIn,


FROM
#TMP_WHSE w

 

其中,SELECT Top 1 JS_Lead FROM #TMP_SHIP s WHERE s.JS_Lead=w.JS_Ship
SELECT Top 1 JK_Consol FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship
SELECT Top 1 JV_Vessel FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship
SELECT Top 1 JV_voyage FROM #TMP_Vessel v WHERE v.JS_Ship=w.JS_Ship

这些都是select同一表且条件也相同,能否将这些语句优化、简化?提高执行效率?

Tiger2009的主页 Tiger2009 | 初学一级 | 园豆:181
提问于:2014-08-25 15:16
< >
分享
所有回答(2)
0
SELECT
 w.Id,
 w.JJ_Consignment,
 w.JU_PK,
 s.JS_Lead,
 w.JS_Ship,
v.JK_Consol,
 v.JV_Vessel,
 v.JV_voyage,

w.JU_Planned,

 w.JU_ActualIn,


 FROM
 #TMP_WHSE w
inner join #TMP_SHIP s on s.JS_Lead
=w.JS_Ship inner join #TMP_Vessel v on v.JS_Ship=w.JS_Ship
519740105 | 园豆:5810 (大侠五级) | 2014-08-25 15:39
0

用好视图。

Firen | 园豆:5483 (大侠五级) | 2014-08-26 06:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册