mysql中给查询结果添加序号

当我们想为查询结果添加序号的时候可以这样写

SELECT @rowid:=@rowid+1 allid, pan_number, receive_person,time_note, url,unit_name,id
FROM(
SELECT a.pan_number,d.F_RealName receive_person, a.time_note,b.url, c.unit_name, c.id
FROM medium_receiptlist_pan a
left join medium_receiptlist_voucher b on a.pan_number = b.pan_number
left join r_counterpart_unit c on a.company = c.id
left join hswj_user d on a.receive_person = d.F_Id
WHERE
pan_logo = '%s'
ORDER BY a.add_time DESC) a, (SELECT @rowid:=0) b

mysql中给查询结果添加序号

 思想:事先定义一个变量,通过变量的递加以及虚拟表的联查达到生成序列号的目的。

上一篇:mysql中给查询结果添加序号列


下一篇:SQL查询结果增加序号列