1.排名
hospital_id, vcc_id, fee_type相同的情况下,create_time升序排名
select * FROM (
SELECT @rownum:=@rownum+1 AS rownum,
IF(@x=concat(uo.hospital_id,uo.vcc_id,uo.fee_type),@rank:=@rank+1,@rank:=1) rank,
@x:=concat(uo.hospital_id,uo.vcc_id,uo.fee_type),
hospital_id, vcc_id, fee_type,create_time,update_time,id
from
(
select *
from hospital_vaccine_inventory
where(hospital_id, vcc_id, fee_type) IN(
select hospital_id, vcc_id, fee_type
from(
select hospital_id, vcc_id, fee_type, count(*)
from tb_vaccine_inventory
GROUP BY hospital_id, vcc_id, fee_type
HAVING COUNT(*)> 1) t)
) uo,(SELECT @rownum:=0,@rank:=0) init
order by hospital_id, vcc_id, fee_type, create_time asc
) result
where hospital_id=3490