2

我想每个 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
4

1 回答 1

2

采用UNION

SELECT ID, (ID*2) as CustomVal FROM tableNAme
UNION ALL
SELECT ID, (ID*4) as CustomVal FROM tableNAme
ORDER BY ID
于 2013-01-17T06:40:59.843 回答