sql联合顺序
我有一张桌子,上面有学生的姓名和身高。我想要一个查询,按字母顺序对身高高于 150 厘米的学生进行排序,对身高低于 150 厘米的学生按姓名降序排列。
像这样的事情:
(select * from students where height >= 150 order by name)
union
(select * from students where height < 150 order by name desc)
它不起作用,因为联合弄乱了子查询中行的顺序。我知道这是正常的,联合输出一个集合,并且在一个集合中的顺序并不重要。有类似追加的东西吗?
I have a table students with names and heights. I want a query that order students higher that 150cm alphabetically and students smaller than 150cm in descending order of their names.
Something like this:
(select * from students where height >= 150 order by name)
union
(select * from students where height < 150 order by name desc)
it's not working because union mess up the order of the rows in subqueries. I know it's normal, union output a set and in a set the order it's not important. Is there something like append?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
样本输出
sample output