我在 db2 中有下表:
| ID | 人 1 | 人 2 | 人 3 |
|---|---|---|---|
| 1 | 10 | 12 | 15 |
我現在想進行一個回傳以下內容的查詢:
| ID | 人 |
|---|---|
| 1 | 10 |
| 1 | 12 |
| 1 | 15 |
我怎樣才能在 db2 中做到這一點?
提前致謝!
uj5u.com熱心網友回復:
使用聯合:
select id, person1 as person
from the_table
union all
select id, person2
from the_table
union all
select id, person3
from the_table
uj5u.com熱心網友回復:
不多次掃描同一個潛在的大表會更有效。
嘗試這個:
SELECT T.ID, V.PERSON
FROM MYTAB T, TABLE (VALUES T.PERSON1, T.PERSON2, T.PERSON3) V (PERSON);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/354043.html
上一篇:根據條件洗掉
