Got this bit of SQL as an update to the script, I tried to add a working round so as not to include the table that will be updated as a sentence in the statement, so using subqueries, but struggling to get this to work.
In essence, I need to update the vailue in table 1 with the sum of the fields in table 2, but only where the other two fields are the same across multiple tables and based on field6, the restriction applies to the update clause.
UPDATE table1 W SET Field1=(SELECT field2 FROM (SELECT A.id, B.field3, SUM(A.field2) AS field2 FROM table2 A, table3 B, table4 P WHERE A.id=B.id AND P.field6=B.field6) B ) WHERE W.field6=B.field6
In a real-world example, select the amount of points missed in a rugby game when a rugby player participated in the match. table 2 contains the results (including assessment), table 3 contains the tables of the teams, and tables 1 and 4 are the same table of players that needs to be updated.
Hope this is clear enough and someone can point me in the right direction.
Tried the following:
UPDATE $WSLKEEP W, $WSLFIX A, $WSLFIXPLAY B SET W.F_CONCEDED=SUM(A.F_AGAINST) WHERE A.F_ID=B.F_GAMEID AND B.F_NAME=W.F_NAME"
but now stuck: Invalid use of group function
Yours faithfully
source share