sql - mySql update with the sum() of rows -
"id" "type" "parent" "country" "votes" "percent" "1" "1" "0" "us" "100" "0" "2" "1" "0" "us" "50" "0" "3" "100" "0" "us" "150" "0" ->150 = sum(votes) type = 1 , country = country "4" "1" "0" "se" "50" "0" "5" "1" "0" "se" "25" "0" "6" "100" "0" "se" "75" "0" ->75 = sum(votes) type = 1 , country = country
i'm trying update type=100
totals of type=1
respective countries.
i've been struggling sql , seem going nowhere. basically, i'm trying update votes type=100 sum of type = 1 respective countries. i've been trying tweak this, seem failing completely. can pls help?
update likes p join likes h on p.country = h.country , (p.type=1) , h.type=1 set p.votes=sum(h.votes) p.type=100;
update tablename inner join ( select country, sum(votes) totalvotes tablename type = 1 group country ) b on a.country = b.country set a.votes = b.totalvotes a.type = 100
Comments
Post a Comment