Thursday, 5 September 2013

MySQL Total Sum Update

MySQL Total Sum Update

SELECT id,100.0/(SELECT SUM(points) FROM data)*points AS reward,points
FROM data;
The first problem I have is that I don't think this is efficient to run
the inner select so many times, what is the best join to use.
The second problem is I am using the resulting dataset to generate
hundreds of individual update queries, how can I update from this from the
select in one query?
i.e
UPDATE aggregate AS a SET a.reward=a.reward+data.reward
SELECT ...
WHERE a.dataid = data.id

No comments:

Post a Comment