我有一个包含4行且保存了DateTime值的表。
查询:
SELECT row1, row2, row3, row4 FROM table;
显示了这个结果:
+------------+------------+------------+------------+
| row1 | row2 | row3 | row4 |
+------------+------------+------------+------------+
|01.01.2014 |null |null |31.12.2018 |
|null |17.08.2015 |01.12.2050 |null |
|02.01.2010 |null |28.03.2067 |null |
+------------+------------+------------+------------+
但我希望将这些日期组合并命令为一行,如:
+------------+
| rows |
+------------+
|01.01.2014 |
|02.01.2010 |
|17.08.2015 |
|01.12.2050 |
|28.03.2067 |
|31.12.2018 |
+------------+
我必须使用什么查询来获得我想要的结果?
提前致谢
答案 0 :(得分:2)
SELECT row1 AS rows FROM table WHERE row1 IS NOT NULL
UNION ALL
SELECT row2 AS rows FROM table WHERE row2 IS NOT NULL
UNION ALL
SELECT row3 AS rows FROM table WHERE row3 IS NOT NULL
UNION ALL
SELECT row4 AS rows FROM table WHERE row4 IS NOT NULL
ORDER BY rows DESC;
会做我想要的。
您是否有关于该问题的更多信息,例如表格和列名称。