以下CTE查询运作良好:
;WITH QResult AS
(SELECT
ROW_NUMBER() OVER (ORDER BY Ad_Date DESC) AS Row,
*
FROM [vw_ads]
)
SELECT
Co1l, Col2,
MAX(Row) OVER()
FROM QResult
我需要的是select top(10)
来自此查询,我尝试了以下
Select top (10) from With ...
但它引发了以下异常:
关键字'with'附近的语法不正确。如果这个陈述是 公用表表达式,xmlnamespaces子句或更改跟踪 context子句,前一个语句必须以a结尾 分号。
如何从WITH Query中选择聚合函数?
答案 0 :(得分:2)
没试过..
;WITH QResult AS (
SELECT ROW_NUMBER() OVER (ORDER BY Ad_Date DESC) AS Row, * FROM [vw_ads] )
SELECT top(10)
Co1l, Col2,
MAX(Row) OVER() FROM QResult