抓出每個 Block_Id 中, End_Date 最小的資料.
語法 A:
With TempBlock as (
Select *,
ROW_NUMBER() OVER(PARTITION BY B.Block_Id ORDER BY B.End_Date, B.Id) AS rk
from BlockData B Where IsDelete = 'N' and End_Date >= getDate())
Select * from TempBlock Where rk = 1
語法 B:
Select * from (
Select *,
ROW_NUMBER() OVER(PARTITION BY B.Block_Id ORDER BY B.End_Date, B.Id) AS rk
from BlockData B Where IsDelete = 'N' and End_Date >= getDate()) TempBlock
Where rk = 1