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。就是我们想要的。

posted @ 2019-09-10 19:06  Herenwei_Wayne  阅读(810)  评论(0编辑  收藏  举报