mysql查询记录添加序列号,数据相同的序列号一样

SELECT	
		a.id gunId,
		a.gun_no gunNo,
		a.gun_name gunName,
		a.qr_code qrCode,
		b.run_status runStatus,
		b.oper_status operStatus,
		c.addr gunAddr,
		ca.id gunModelId,
		ca.model_name gunModelName,
		ca.connector_type gunConnectorType,
		cb.id gunBrandId,
		cb.brand_name gunBrandName,
		 d.id pileId,
		d.pile_no pileNo,
		d.pile_name pileName,
		d.equip_addr_type equipAddrType,
		d.connect_type connectType,
		d.power_allot_type powerAllotType,
		d.avg_power avgPower,
		d.nameplate_no nameplateNo,
		d.protocol_id protocolId,
		e.id pileModelId,
		e.model_name pileModelName,
		eb.id pileBrandId,
		eb.brand_name pileBrandName,
		f.addr pileAddr,
		g.id stationId,
		g.station_no stationNo,
		IFNULL(g.station_short_name,g.station_name) stationName,
		g.org_id orgId,
		t.rank
	
FROM
c_gun a
LEFT JOIN c_gun_run_status b ON b.gun_id = a.id AND b.deleted = 0
LEFT JOIN c_equip_addr c ON a.id = c.equip_id AND c.equip_type = '0202' AND c.deleted = 0
LEFT JOIN c_gun_model ca ON ca.id = a.model_id AND ca.deleted = 0
LEFT JOIN c_equip_brand cb ON cb.id = ca.brand_id AND cb.deleted = 0
INNER JOIN c_pile d ON d.id = a.pile_id AND d.deleted = 0
LEFT JOIN c_pile_model e ON e.id = d.model_id AND e.deleted = 0
LEFT JOIN c_equip_brand eb ON e.brand_id = eb.id AND eb.deleted = 0
LEFT JOIN c_equip_addr f ON f.equip_id = d.id AND f.equip_type = '0201' AND f.deleted = 0
LEFT JOIN c_station g ON d.station_id = g.id AND g.deleted = 0

>  LEFT JOIN (SELECT t.pile_id, (@rowno:=@rowno+1) AS rank  FROM 
> (SELECT  pile_id FROM c_gun WHERE deleted = 0 GROUP BY pile_id) t, 
> (SELECT  @rowno:=0) rowNO   ) t ON d.id=t.pile_id

WHERE a.deleted = 0 ORDER BY a.pile_id,a.gun_no

你可能感兴趣的:(mysql)