我有陈述
SELECT a FROM X UNION SELECT b FROM Y UNION SELECT c FROM Z;
我想对output进行排序,首先是a的行,然后是b,最后是c。我试过使用 GROUP BY 以及 ORDER BY 但我不断地犯错误,看不出逻辑,看不出它应该如何工作。
GROUP BY
ORDER BY
6bc51xsx1#
你可以做:
select a from ( SELECT a, 1 as display_order FROM X UNION ALL SELECT b, 2 FROM Y UNION ALL SELECT c, 3 FROM Z ) w order by display_order
1条答案
按热度按时间6bc51xsx1#
你可以做: