sql查询 生成列号

select @row_num totalcount,1 as pageIndex, 3 as pageSize,result_order.*
from account_report as ar inner join (
select @row_num:=@row_num+1 AS row_num ,a.name as aName,a.transaction_type,r.report_date,r.name as rName,r.submit_time,r.deadline,r.`status`,r.id as reportId
from account a,account_report r ,(SELECT @row_num:=0) AS rowvar
where r.account_id=a.id and a.transaction_type in (2) and r.`status` in (0) and r.`type` in (0)
)
AS result_order on ar.id=result_order.reportId

and result_order.row_num>(3*(1-1)) and result_order.row_num<=(3*1)
order by result_order

原文地址:https://www.cnblogs.com/dasheng-maritime/p/5781409.html