sql server 按照字段分组 重新设置组序号
SELECT cpr.Id, cpr.CreateTime, cpr.Number FROM CarParkingRegistration cpr
SELECT CONCAT(FORMAT(cpr.CreateTime, 'yyyyMMdd'), FORMAT(ROW_NUMBER() OVER (PARTITION BY CAST(cpr.CreateTime AS DATE) ORDER BY CAST(cpr.CreateTime AS DATE)), '000')) FROM CarParkingRegistration AS cpr WHERE cpr.StartDate IS NOT NULL
重点在于 PARTITION BY 按照时间分组。再定义出ROW_NUMBER。就是我们想要的。