我在Union all
. 我知道我不能这样做。但是谁能帮帮我。
SELECT
ID,
date1,
date2 row_number() OVER (PARTITION BY ID ORDER BY date1 DESC ) as RN1,
1 as Range
FROM
(
SELECT ID,date1,
rn = row_number() OVER (PARTITION BY ID ORDER BY date1 )
FROM listing_History (nolock)
WHERE [date1] <= CONVERT(DATE,DATEADD(MONTH, -6, GETDATE())) AND
ID in (SELECT txt FROM [dbo].[fn_ListToTable](@listStr, ','))
) AS A ORDER BY date1 DESC, date2 DESC
UNION ALL
SELECT
ID,
Date1,
date2 row_number() OVER (PARTITION BY ID ORDER BY date1 DESC ) as RN1,
1 as Range
FROM
(
SELECT
ID,
date1,
rn = row_number() OVER (PARTITION BY ID ORDER BY date1 )
FROM listing_History (nolock)
WHERE [status_date] <= CONVERT(DATE,DATEADD(MONTH, -3, GETDATE()) -1)
AND
ID in (SELECT txt FROM [dbo].[fn_ListToTable](@listStr, ','))
) AS A ORDER BY date1 DESC,date2 desc