mySql往一个表中增加数据,如果已经有就更新,没有就插入数据:
replace into unitoll_total(ListNO,StarTime,EndTime,OwnerCode,Gross,ICType,SquadDate,ID)
select m.ListNO, m.StarTime,m.EndTime, m.OwnerCode, m.Gross, m.ICType, m.SquadDate, m.ID
from (
select t.ListNO, t.SquadDate as StarTime, t.SquadDate as EndTime,
t.OwnerCode, sum(t.toll) as Gross, t.ICType, t.SquadDate,
ifnull((select t1.ID from unitoll_total t1
where t1.SquadDate=t.SquadDate and t.ICType=t1.ICType),UUID()) as ID
from unitoll_detail t
where t.SquadDate="20150928T000000"
group by t.ICType
order by t.SquadDate desc
) m;
mySql往一个表中增加数据,如果已经有就更新,没有就插入数据
最新推荐文章于 2022-10-20 15:59:09 发布