mysql 分組後,在每個組中排序
阿新 • • 發佈:2019-02-03
如下資料:
活動id 批次id 批次開始時間 期望序號
1 1 09:00 1
1 2 09:01 2
1 3 09:05 3
2 4 08:55 1
2 5 09:00 2
.........
活動id :choose_room_activity_id
批次id: choose_room_batch_id
開始時間: start_date
表名:ztc_choose_room_batch
select a.choose_room_activity_id,a.choose_room_batch_id,count(*) as 序號,a.start_date from ztc_choose_room_batch as a
INNER JOIN ztc_choose_room_batch as b
ON a.choose_room_activity_id=b.choose_room_activity_id and a.start_date >= b.start_date group by a.choose_room_activity_id,a.choose_room_batch_id ORDER BY a.start_date asc;