这,有什么规律吗还是单纯是分组序号
--
分组序号
SELECT A.*,B.RN FROM TABLE1 A LEFT JOIN ( select A.* ,ROW_NUMBER() OVER ( ORDER BY 字段1 ,字段2) RN FROM ( SELECT 字段1, 字段2 FROM table1 group by 字段1 ,字段2 ) A ) B ON A.字段1=B.字段1 and a.字段2=b.字段2
SELECT
@r:=CASE WHEN @rank=aa.字段2 THEN @r+1 ELSE 1 END AS '组内序号',
@rank:=aa.字段2 AS '分组',
aa.*
FROM
(SELECT
字段1,
字段2
FROM 表名
group by
) aa ,(SELECT @r:=0 ,@rank:='') bb
ORDER BY aa.字段2,aa.字段1 DESC