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`

     

  • 示例:

  • MySql(分组)排序编号_第1张图片

 

SET @i=0;
CREATE TABLE user_order AS 
SELECT
	(@i:=@i+1) AS order_id,
	order_uid,
    order_date
from order_list group by order_uid

你可能感兴趣的:(mysql)