SELECT TOP 100 PERCENT 不按后面的order by 排序


  項目中,由於需要把3個狀態的任務合並顯示,並且按照任務由近及遠的順序排序,類似於下面的語句

 

select * from (select top 100 percent taskid,state from looptask where state=1 order by taskid desc )m
union all
select * from (select top 100 percent taskid,state from looptask where state=2 order by taskid desc )n
union all
select * from (select top 100 percent taskid,state from looptask where state=3 order by taskid desc )t

但是在執行中,發現結果並沒有按照設定的排序顯示。

后來發現這個方法可行,把100改成99.9999999 這樣使用select top 99.999999 PERCENT,一般來說,你的數據庫不超過1億條數據,使用99.999999 PERCENT都不會使你遺漏數據。需要的話再添倆9


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM