我希望每个ID都有2个Custom_Column
值。
我怎么能这样做?
示例表:
ID
1
2
3
示例查询:
SELECT id, (id*2) as Custom_Value, (id*4) as Custom_Value FROM numbers
响应:
ID Custom_Value
1 2
1 4
2 4
2 8
3 6
3 12
答案 0 :(得分:2)
使用UNION
SELECT ID, (ID*2) as CustomVal FROM tableNAme
UNION ALL
SELECT ID, (ID*4) as CustomVal FROM tableNAme
ORDER BY ID