加入案例陈述

时间:2017-05-03 02:52:33

标签: sql oracle

我正在尝试将以下查询重新编写到连接条件中,并从字段中获取描述。你能帮我把查询改写成连接吗?..

SELECT DESCRIPTION FROM apps.FND_FLEX_VALUES_VL
  WHERE FLEX_VALUE = T.SEGMENT1
    AND FLEX_VALUE_SET_ID = 1015327)  SEGMENT1_DESC,
  T.SEGMENT2      SEGMENT2,
(SELECT DESCRIPTION FROM apps.FND_FLEX_VALUES_VL
WHERE FLEX_VALUE = T.SEGMENT2
  AND FLEX_VALUE_SET_ID = 1015259) SEGMENT2_DESC,
T.SEGMENT3                        SEGMENT3,            
(SELECT DESCRIPTION FROM apps.FND_FLEX_VALUES_VL
WHERE FLEX_VALUE = T.SEGMENT3
  AND FLEX_VALUE_SET_ID = 1015328)  SEGMENT3_DESC,
T.SEGMENT4 SEGMENT4,
(SELECT DESCRIPTION FROM apps.FND_FLEX_VALUES_VL
WHERE FLEX_VALUE = T.SEGMENT4
  AND FLEX_VALUE_SET_ID = 1015329)  SEGMENT4_DESC,
 T.SEGMENT5  SEGMENT5,
 (SELECT DESCRIPTION FROM apps.FND_FLEX_VALUES_VL
WHERE FLEX_VALUE = T.SEGMENT5
  AND FLEX_VALUE_SET_ID = 1015330

1 个答案:

答案 0 :(得分:0)

行。所以这个问题真的太不完整了,无法给出答案。但是,我对你可能想要的内容有所了解。

WITH flex_vl AS
  (SELECT flex_value, description 
   FROM   apps.FND_FLEX_VALUES_VL
   WHERE FLEX_VALUE_SET_ID IN(1015259,1015328,1015329,1015330,1015327)
SELECT t.some_data, t.segment1, vl1.description,t.segment2,vl2.description,
       t.segment3,vl3.description,t.segment4,vl4.description,t.segment5,     vl5.description
FROM   my_table t
       INNER JOIN 
       flex_vl vl1 ON vl1.flex_value = t.segment1                        
       INNER JOIN 
       flex_vl vl2 ON vl2.flex_value = t.segment2
       INNER JOIN 
       flex_vl vl3 ON vl3.flex_value = t.segment3
       INNER JOIN 
       flex_vl vl4 ON vl4.flex_value = t.segment4
       INNER JOIN 
       flex_vl vl5 ON vl5.flex_value = t.segment5

你需要记住,我不得不猜测你要问的一些内容,但实质上这是从表中别名为'T'(在你的查询中)到使用不同SEGMENT的FND_FLE_VALUES_VL表的多个连接每次都有价值。 (另外,这还没有经过测试)