SELECT
s.id,s.image_path,s.attach_title,s.attach_required,s.`task_name`,s.originalFilename original,
@r:= CASE WHEN @asset_code=s.asset_code THEN @r+1 ELSE 1 END AS rowNum,
@asset_code:=s.asset_code AS asset_code
FROM
(SELECT i.*, f.attach_title,f.attach_required,m.`task_name`,IFNULL(a.`asset_code`,'') asset_code
FROM tfam_asset_checkimage i
LEFT JOIN tfam_asset a ON a.id = i.`card_id`
LEFT JOIN tfam_asset_checkplan_main_attach f ON f.id = i.`attach_category`
LEFT JOIN tfam_asset_checkplan_main m ON f.`main_id` = m.id
#WHERE i.main_id = ? AND i.`attach_category` = ?
ORDER BY a.`asset_code`) s,(SELECT @r:=0,@asset_code:='') b
按所某字段进行排序,定义变量r序号和某字段初始值,依次赋值,当前值等于上一条记录值则+1否则=1
版权声明:本文为qq_38053711原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。