MySql(分组)排序编号

不分组直接添加顺序

  • 代码
SELECT @rownum:=@rownum+1 AS rownum, a.cus_number
FROM (SELECT @rownum:=0) r, invest

分组排序编号

  • 代码
SELECT a.`cus_number`,a.`id`,count(*) AS '排名',a.`invest_count`
FROM borrow_tender   a 
LEFT JOIN borrow_tender  b
on a.`cus_number` = b.`cus_number` 
and a.`id`>= b.`id`
GROUP BY a.`cus_number`, a.`id`

示例

image.png

你可能感兴趣的:(MySql(分组)排序编号)