除非另外還指定了 TOP 或 FOR XML,否則,ORDER BY 子句在視圖、內嵌函式、派生表、子查詢,xmlorder

來源:互聯網
上載者:User

除非另外還指定了 TOP 或 FOR XML,否則,ORDER BY 子句在視圖、內嵌函式、派生表、子查詢,xmlorder

報錯:

除非另外還指定了 TOP 或 FOR XML,否則,ORDER BY 子句在視圖、內嵌函式、派生表、子查詢和通用資料表運算式中無效。


只要我們在嵌套子查詢視圖裡面加入:top 100 percent即可

例如:

select * from (select top 100 percent * from tb   order by col desc) as a order by col desc



SQL 陳述式查詢,對於 TOP、ORDER BY 語句使用問題,想了很久也沒想明白,望指點下

應該一句話就可以了
select top 100 欄位1 from 表1 where 欄位1 like '2%' order by 欄位2
或者
SELECT TOP 100 a.欄位1 FROM (select * from 表1 where 欄位1 like '2%'order by 欄位2) as a order by a.欄位1
 
對於SQL查詢結果排序問題

第一,語句錯誤;除非另外還指定了 TOP 或 FOR XML,否則,ORDER BY 子句在視圖、內嵌函式、派生表、子查詢和通用資料表運算式中無效。
第二,回答你的問題,結果不會按照子查詢中的排序結果輸出,語句如下:
select * from (select TOP 100 PERCENT * from table1 AS A order by A.field1 DESC) newTable
最後得出的結果等價於
select * from table1 AS A
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.