sql - MYSQL- Update Row Based on Fields From Another Row In Same Table -
i have "matches" table holds matches various games. looks (team1 , team2 correspond team ids)
team1|team2|tourney_identity|tourney_next|winner 5 6 1 3 6 7 8 2 3 7 0 0 3 5 0
team 0 "tbd" , placeholder when teams arent decided yet.
i need query can run continuously grab winner match, update match has matching identity tourney_next
it needs able see if needs update team1 or team2
the final table should this:
team1|team2|tourney_identity|tourney_next|winner 5 6 1 3 6 7 8 2 3 7 6 7 3 5 0
this current subquery have isnt working, place start
update matches m,( select *, case when t1score > t2score team1 else team2 end winner matches isnull(round_id)=false , tourney_next<>0 , event_id=$event order tourney_next) m2 set m.team1= case when (m.team1=0 or isnull(m.team1)=true) , m.team2!=winner winner else m.team1 end , m.team2= case when (m.team1!=0 , isnull(m.team1)=false) , m.team1!=winner winner else m.team2 end m.tourney_identity=m2.tourney_next , m.event_id=m2.event_id
Comments
Post a Comment