When using an aggregate function, such as SUM, COUNTor MAX, and you also want to select other columns from your data, you need to group your data by other columns used in your query.
So you need to write something like:
WITH QResult AS
(SELECT
ROW_NUMBER() OVER (ORDER BY Ad_Date DESC) AS Row,
*
FROM [vw_ads]
)
SELECT Co1l, Col2, MAX(Row)
FROM QResult
GROUP BY Col1, Col2
, - . * GROUP BY.
: , , - :
(. № 2 - , )
WITH QResult AS
(SELECT
ROW_NUMBER() OVER (ORDER BY Ad_Date DESC) AS Row,
*
FROM [vw_ads]
)
SELECT
Co1l, Col2,
MaxRow = (SELECT MAX(Row) FROM QResult)
FROM QResult
Row CTE, .
№2: :
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
, , - , . , !