SQL 帮助:值相关排序?
我正在尝试编写一个 SQL 查询来执行一些复杂的排序。我有一个包含一些记录的表,每个记录都有三个重要字段:
- Group_ID
- Modified_Order
- Created_Order
现在,我尝试编写一个查询,首先按组 ID 对这些记录进行排序。然后,如果组 ID 为 1,则按“修改顺序”对这些结果进行排序。如果组ID为2,则按“创建顺序”对它们进行排序。不会出现非 1 或 2 的组 ID。换句话说,我希望结果如下图所示。
如何编写查询的“ORDER BY”或“GROUP BY”部分来执行此操作?
I am trying to write a SQL query that does some complex sorting. I have a table with some records, each having three important fields:
- Group_ID
- Modified_Order
- Created_Order
Now, I am trying to write a query that first sorts these by the group ID. Then if the group ID is 1, sort those results by their "modified order". If the group ID is 2, sort them by their "created order". Group ID's that are not 1 or 2 will not occur. In other words, I want the results to look like the picture below.
How can I write the "ORDER BY" or "GROUP BY" part of my query to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样:
How about: