SQL中有沒有一種方法可以映射重複條目並從另一個表中獲取數據。我需要映射表2中的原始文件名,但數據來自表1,並使用新的文件名作爲映射參考?我試圖做ROW_NUMBER與分區,但我不會去任何地方來自另一個表的SQL映射重複條目
表1:
new filename original filename
text_001.pdf test1333.pdf
text_001.pdf test4443.pdf
hello2332.pdf world1234.txt
hello2332.pdf world3331.txt
表2:
EE new filename
00001 text_001.pdf
00001 text_001.pdf
00002 hello2332.pdf
00002 hello2332.pdf
輸出繼電器表:
EE new filename original filename(entries coming from table 1)
00001 text_001.pdf test1333.pdf
00001 text_001.pdf test4443.pdf
00002 hello2332.pdf world1234.txt
000002 hello2332.pdf world3331.txt
我建議加入!也許是一個LEFT JOIN,如果你還想從table2中的文件沒有被重命名的行 – jarlh
'select * from table2 t2 join table1 t1 on t1.new_filename = t2.new_filename'? –
沒有通用的方法來做到這一點,因爲第一個表中的新文件名沒有列來分隔重複項。你需要修復你的數據。 –