SELECT
ROW_NUMBER ( ) OVER ( ORDER BY a.FillingDateTime DESC ) AS RowNum,
a.*
FROM
(
SELECT
ROW_NUMBER ( ) OVER ( partition BY w.GasCylinderGuid ORDER BY w.FillingDateTime DESC ) rn,
w.*,
f.FillingStationName,
r.RegionInfoName
FROM
data.GasCylinderWorkFlow w WITH ( nolock )
LEFT JOIN base.FillingStation f WITH ( nolock ) ON w.FillingStationGuid = f.FillingStationGuid
LEFT JOIN auth.RegionInfo r WITH ( nolock ) ON r.RegionInfoCode = LEFT ( f.DivisionCode, 6 )
WHERE
w.Status = 0
AND f.DivisionCode LIKE '320509%'
AND w.FillingDateTime >= '2022-11-12'
AND '2022-11-13' > w.FillingDateTime
) a
WHERE
a.rn=1
sqlserver groupby分组后取第一个sql
最新推荐文章于 2023-06-26 23:10:13 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)