執(zhí)行sql語句:
select * from (
select * from tab where ID>20 order by userID desc
) as a order by date desc
邏輯上看著挺對 但是報錯:
除非另外還指定了 TOP 或 FOR XML缨硝,否則,ORDER BY 子句在視圖评凝、內(nèi)聯(lián)函數(shù)追葡、派生表、子查詢和公用表表達式中無效奕短。
只要我們在嵌套子查詢視圖里面加入: top 100 percent 即可
select * from (
select?top 100 percent?* from tab where ID>20 order by userID desc
) as a order by date desc