我需要在 WITH 查询中进行查询,类似于:
; WITH #table1
(
SELECT id, x from ... WHERE....
UNION ALL
SELECT id, x from ... WHERE...
)
WITH #table2
(
SELECT DISTINCT tbl_x.*,ROW_NUMBER() OVER (order by id) as RowNumber
WHERE id in ( SELECT id from #table1)
)
SELECT * FROM #table2 WHERE RowNumber > ... and ...
我必须在第一个WITH上使用WITH,然后在第二个WITH上使用SELECT,我该怎么做?
WITH
关键字只需使用一次。 - HABO