mysql - Updating Table2 when data found in table1 -
forgive me if make fool of myself still new mysql queries beyond "basic" kind. have 2 tables of data.
table 1 has data parsed using load , table 2 has data manually entered user information. pulled automatically | delimited file twice day.
the following columns in table1 have data need verify against (there more columns these):
sendid | recid | transamt | transdate | transstatus and following columns table2:
userid | username | currentcapacity | maxcapacity what i'm trying run update userid curentcapacity increased one, when userid found in sendid or recid when transstatus = active. i've tried following:
update table1,table2 set table2.currentcapacity=table2.currentcapacity+1 ( table2.transstatus="active" , (table2.userid = table1.sendid or table1.recid)) this works , currentcapacity increased 1, increased one. effect i'm going set currentcapacity equal sum of transstatus="active".
i tried following , returns "#1111 - invalid use of group function" error:
update table1,table2 set table2.currentcapacity=sum(table1.transstatus) ( table2.transstatus="active" , (table2.userid = table1.sendid or table1.recid)) any suggestions or guidance?
give try if gives desired result, (not manually tested)
update table2 b inner join ( select id, sum(transstatus = 'active') total ( select sendid id, transstatus table1 union select recid id, transstatus table1 ) x group id ) on b.userid = a.id set b.currentcapacity = a.total
Comments
Post a Comment