场景举例,方便理解
test2 表
表格要求用 operate、tid 列分组,并且查询结果生成如下px列序号:
result:
查询语句:
select a.*,
(select count(*) as 序号 from test2 as b where
a.tid=b.tid and a.operat = b.operat
and a.id >=b.id ) as px
from test2 as a ORDER BY operat ,tid;
根据a.tid=b.tid and a.operat = b.operat条件进行分组
根据a.id >=b.id进行序号生成