mysql - Updating with two selects -
"id" "type" "parent" "country" "votes" "percent" "1" "1" "0" "us" "0" "0" "2" "2" "1" "us" "0" "0"//votes = 8 i.e total of id3 votes , id7votes. both have id=2 parent, , id=2 type 2 "3" "3" "2" "us" "4" "0" "7" "3" "2" "us" "4" "0" "19" "3" "1" "us" "4" "0" "4183" "10" "3" "us" "2" "0" "4184" "10" "3" "us" "2" "0" "4185" "10" "7" "us" "2" "0" "4186" "10" "7" "us" "2" "0" "4187" "10" "19" "us" "2" "0" "4188" "10" "19" "us" "2" "0" i'm trying update col type=2 sum of votes id parent. i've been trying below, seem going no since involves 3 statements , i'm backward joins , multiple selects.
update likesd inner join ( select parent, sum(votes) totalvotes likesd type = 3 group parent ) b on a.country = b.country set a.votes = b.totalvotes a.id = b.parent; it's this:
select id likesd type = 2 select sum(votes) totalvotes parent = id update likesd set votes = totalvotes id = parent , country = country any idea how can done. i'm ok 2 selects, third 1 has stuck.
edit: type = 2 repeats in table
update likesd a, (select parent, sum(votes) totalvotes likesd group parent) b set a.votes = b.totalvotes a.type = 2 , a.id = b.parent
Comments
Post a Comment