自定义列的多个值

时间:2013-01-17 06:38:19

标签: mysql sql

我希望每个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

1 个答案:

答案 0 :(得分:2)

使用UNION

SELECT ID, (ID*2) as CustomVal FROM tableNAme
UNION ALL
SELECT ID, (ID*4) as CustomVal FROM tableNAme
ORDER BY ID