在SQL中将一行拆分为两行

时间:2013-11-08 09:03:27

标签: sql

我有一个包含以下列的表

PAX_NO | AMOUNT_ONE | AMOUNT_TWO | PAX_NO_LASTYEAR | AMOUNT_ONE_LASTYEAR | AMOUNT_TWO_LASTYEAR
45     |  56.54     |  43.23     |   23            |      23.43          |       78.43
69     |  21.11     |  51.19     |   20            |      11.23          |       55.99

我需要按以下方式获取

PAX_NO  |  AMOUNT_ONE    | AMOUNT_TWO
45      |      56.54     |    43.23
23      |      23.43     |    78.43
69      |      21.11     |    51.19
20      |      11.23     |    55.99

1 个答案:

答案 0 :(得分:4)

您可以使用UNION ALL

SELECT pax_no, amount_one, amount_two FROM your_table
UNION ALL
SELECT PAX_NO_LASTYEAR, AMOUNT_ONE_LASTYEAR, AMOUNT_TWO_LASTYEAR FROM your_table;