我有一个表格,屏幕截图中给出了数据
.
我只需要获取每个月具有最大Snapshot_Date的记录.
我需要我的结果数据集如下

我怎么能这样做 我需要你的想法.
我试过用
select *
from table
where Snapshot_Date = (select MAX(Snapshot_Date)
from table
where DATEPART(MONTH,Snapshot_Date)=11)
Run Code Online (Sandbox Code Playgroud)
但我需要在这里硬编码月份数!谢谢你的时间!!
SELECT Snapshot_Date, Quantity
FROM
(
SELECT DATENAME(month, Snapshot_Date) MonthName,
Snapshot_Date, Quantity,
ROW_NUMBER() OVER (PARTITION BY DATENAME(month, Snapshot_Date)
ORDER BY Snapshot_Date DESC) rn
FROM tableName
) a
WHERE rn = 1
Run Code Online (Sandbox Code Playgroud)
来源