当我们想为查询结果添加序号的时候可以这样写
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
思想:事先定义一个变量,通过变量的递加以及虚拟表的联查达到生成序列号的目的。