簡體   English   中英

如何根據兩個查詢中的哪一個來對聯合查詢的結果進行排序?

[英]How to Order the Results of a Union Query By Which Of The Two Queries Comes From?

基本上我想要這個:

    SELECT column FROM Table Where column LIKE "%interesting%"
    UNION
    SELECT column FROM Table 
    ORDER BY "the interesting results first, the fillers second." 

如果有趣的結果很少,我會這樣做,以便用隨機的結果填充它們。

您只需要一個ORDER BY

SELECT column
FROM Table 
ORDER BY (CASE WHEN column LIKE '%interesting%' THEN 1 ELSE 2 END);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM