问题
I am running the below code. When I run this code, I get error message:
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
I'm not sure why I am getting this error message. Help is much appreciated.
SELECT a.DELINQ_BUCKET_GROUP, a.vv_count
FROM
(
SELECT DELINQ_BUCKET_GROUP,
CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN
SUM(CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN 1 ELSE 0 END)
ELSE COUNT(DELINQ_BUCKET_GROUP)
END AS vv_count
FROM DCSReporting.dbo.DIM_DELINQUENT_BUCKET
GROUP BY DELINQ_BUCKET_GROUP
ORDER BY vv_count DESC
) a
WHERE rownum<=100
回答1:
If you are using
SQL Server 2012
or later version, useOffset 0 Rows
afterOrder By
:
SELECT Id,
Name
FROM Table
ORDER BY Id
OFFSET 0 ROWS
Hope this helps.
来源:https://stackoverflow.com/questions/36697511/sql-server-query-error-order-by-clause-is-invalid-in-views