我有表避免在查詢
M,R,G,d,PT和PI
PI具有與所有其他表的關係。 有一個父 - M,R,G和D的子關係
實施例:型號ID將在那裏在M和R 範圍ID將在那裏在R和G 級ID將在那裏在G中和d
要知道其被髮布的衍生物,示例是如下
SELECT D.DERIVATIVE_ID
FROM PRD.DERIVATIVE D
JOIN PUB.PUBLISHED_ITEM PI ON PI.PUBLISHED_OBJECT_ID = D.DERIVATIVE_ID
AND PI.PUBLISHED_OBJECT_TYPE = 'DERIVATIVE'
JOIN PUB.PUBLISHED_TARGET PT ON PI.PUBLISHED_TARGET_ID = PT.PUBLISHED_TARGET_ID
WHERE D.DERIVATIVE_ID = 683239
要知道其被髮布的模型,一個例子是如下面
SELECT *
FROM PRD.MODEL M
JOIN PUB.PUBLISHED_ITEM PI ON PI.PUBLISHED_OBJECT_ID = M.MODEL_ID
AND PI.PUBLISHED_OBJECT_TYPE = 'MODEL'
JOIN PUB.PUBLISHED_TARGET PT ON PI.PUBLISHED_TARGET_ID = PT.PUBLISHED_TARGET_ID
WHERE M.model_id = 257
我想編寫一個查詢,顯示模式,其衍生物公佈,但不是模型(模型沒有公佈)
這裏是我試過了,您的意見將是有益的
SELECT *
FROM PRD.MODEL M
JOIN PUB.PUBLISHED_ITEM PI ON PI.PUBLISHED_OBJECT_ID = M.MODEL_ID
AND PI.PUBLISHED_OBJECT_TYPE = 'MODEL'
JOIN PUB.PUBLISHED_TARGET PT ON PI.PUBLISHED_TARGET_ID <> PT.PUBLISHED_TARGET_ID
JOIN PRD.RANGE R ON R.MODEL_ID = M.MODEL_ID
JOIN PRD.GRADE G ON G.RANGE_ID = R.RANGE_ID
JOIN prd.DERIVATIVE D ON D.GRADE_ID = G.GRADE_ID
AND D.DERIVATIVE_ID IN (
SELECT D.DERIVATIVE_ID
FROM PRD.DERIVATIVE D
JOIN PUB.PUBLISHED_ITEM PI ON PI.PUBLISHED_OBJECT_ID = D.DERIVATIVE_ID
AND PI.PUBLISHED_OBJECT_TYPE = 'DERIVATIVE'
JOIN PUB.PUBLISHED_TARGET PT ON PI.PUBLISHED_TARGET_ID = PT.PUBLISHED_TARGET_ID)
同樣在上面的查詢中,我該如何避免使用「IN」?
THX重新格式化,你用什麼工具? – Beth 2014-11-20 17:25:33
我使用SQL提示 - 非常值得花錢! – 2014-11-20 17:30:09