有沒有一種方法可以構建一個SQL語句,它將幫助我根據狀態檢索活動記錄,然後引用另一個字段中存儲的oldids?SQL從包含逗號分隔鍵的字段中選擇
假設我想將下面的數據加入到另一個表中。對於ID = 4,意味着暗示ID 1,3和4結合在一起,倖存的記錄是4.
所以,當我想要與另一個表一起加入時,如何將scvid 104鏈接到ID 1,3和4的交易?
select *
from tbl
where scvid in (id, oldids)?
的樣本數據:
scvid id oldid status
------------------------------
101 1 NULL 0
102 2 NULL 1
103 3 NULL 0
104 4 [1,3] 1
不要將數據存儲爲逗號分隔的項目。這隻會導致你很多麻煩。 – jarlh
你使用什麼數據庫(MSSQL,MySql,....)? – valex