Select DISTINCT ItemId
From Item
Select ItemId
From Item
GROUP BY ItemId
Select ItemId,CreatedDate
From ( Select ItemId,CreatedDate ,
ROW_NUMBER() Over (Partition By ItemId Order By CreatedDate Desc) As Sort From Item) TMP_S
Where TMP_S.Sort=1
- Distinct:取唯一值
- Group By:群組方式
- ROW_NUMBER() OVER (PARTITION BY partition欄位 ORDER BY 排序欄位)
- 將每一筆記錄依序塞入一個順序值,然後在where取出編號1的值就是唯一值了。