我有这样的疑问:
SELECT
CurrentAccountID
, IncomeBYR + IncomeConvertBYR AS AmountBYR
, IncomeUSD AS AmountUSD
, [Date] AS ExecutionDate
FROM CTE2
ORDER BY [Date]
我需要将AmountBYR和AmountUSD组合成一个具有相同日期的列。 结果集如下:
CurrentAccountID AmountTotal ExecutionDate
3 2383410.00 2010-02-13
3 -159 2010-02-13
... .... .....
在一个Select查询中存在某种方式吗?
答案 0 :(得分:3)
我会使用UNION ALL。
像
这样的东西SELECT
CurrentAccountID
, IncomeBYR + IncomeConvertBYR AS AmountTotal
, [Date] AS ExecutionDate
FROM CTE2
UNION ALL
SELECT
CurrentAccountID
, IncomeUSD AS AmountTotal
, [Date] AS ExecutionDate
FROM CTE2
ORDER BY [Date]