翻譯值我有一個位置表SQL查詢以檢索輸出
pos_table
與
position_code job_code location_code pos_name BUSINESS_UNIT
1 staff delhi supervisor XYZ
2 supervor manila technical associate ABC
mapping table
table_code source_code business_unit target_code
LOC DELHI XYZ 10
loc MANILA ABC 20
job staff XYZ 01
job supervisor ABC 02
我想它連接映射表,pos_table查詢列,使得
爲JOB_CODE人員映射表target_code的輸出01應該來自 ,使用business_unit和source_code作爲連接。
輸出:
position_code job_code location_code pos_name BUSINESS_UNIT
1 01 10 supervisor XYZ
2 02 20 technical associate ABC
爲了這個,我寫的查詢:
select POSITION_CODE,
coalesce(JOB_MAP.FUSION_HARMONIZED_CODE,JOB_CODE) JOB_CODE,
coalesce(LOC_MAP.FUSION_HARMONIZED_CODE,LOCATION_CODE)LOCATION_CODE
from pos_tab POS_STAG,
MAPPING_TAB LOC_MAP,
mapping_tab job_MAP
where 1=1
and JOB_MAP.source_code||business_unit_name = POS_STAG.JOB_CODE||business_unit_name
and LOC_MAP.TABLE_CODE ='LOC'
and job_map.table_code='JOB'
and LOC_MAP.source_code ||business_unit_name = POS_STAG.LOCATION_CODE||business_unit_name;
,但是這是行不通的,它是rerieving更多的行數
您顯示的數據看起來很不一致;混合大小寫映射表的table_code中,pos表的作業代碼有'supervor'而不是'supervisor'。這是你的實際數據,還是你爲這個問題做好了準備? –
@ AlexPoole-這是一個示例數據..請原諒打字錯誤 –
隨着清理值您的查詢獲得兩行,所以它真的不清楚是什麼問題。請輸入一些實際證明問題的實際數據,並顯示您現在得到的結果以及您想要獲取的數據。 –