如何将两个SQL查询与不同的ORDER BY子句组合在一起 [英] How to combine two SQL queries with different ORDER BY clauses

查看:113
本文介绍了如何将两个SQL查询与不同的ORDER BY子句组合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上看过,但只能找到两个与相同 order by组合的查询.

I looked online, but I could only find two queries combined with the same order by.

第一个查询:

SELECT
  Name
  , Priority
FROM Music
WHERE `Priority` > 0 AND `date` > '2014-10-27 20:04:25'
ORDER BY `Priority` DESC

第二个查询:

SELECT
  Name
  , Priority
FROM Music
WHERE `Priority` = 0 AND `date` > '2014-10-27 20:04:25'
ORDER BY `date`

我需要将第一个查询和第二个查询合并为一个,在其中执行第一个查询,然后执行第二个查询,这给出了完整的列表.

I need to combine the first and the second query into one, where the first query is executed and then the second query is executed giving me a complete list.

推荐答案

不仅是1个查询...优先级都是>或= 0

Is it not just 1 query... Where Priority is both > or = 0

select Name, Priority 
from Music 
where `Priority` >= 0 
AND `date` > '2014-10-27 20:04:25' 
order by `Priority` DESC, `date`

这篇关于如何将两个SQL查询与不同的ORDER BY子句组合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆