I have the following query. It gives me every time the most recent standings in this seisons competition.
Is there a way to update another table with the results of this query?
The code should be (I think):
UPDATE standen
SET speler = speler, jaarweek = MAX(JaarWeek), stand = Stand
SELECT therealselect.*,@row_index:=@row_index+1 Stand from (
SELECT w_seizoen AS Seizoen
, MAX(w_datum)
, speler
, MAX(JaarWeek)
, COUNT(w_wnr) AS "Gespeeld"
, SUM(berpunten) AS "Tot. punten"
, SUM(berpunten)/COUNT(w_wnr) AS Winstperc
, ROUND(SUM(car)/SUM(w_brtn),4)- ROUND(temaken/25,4) AS Moyenne
, MAX(HSerie)/temaken AS "HSerie (%%)"
FROM resultaten
GROUP BY speler
ORDER BY Winstperc DESC, Moyenne DESC
) therealselect,(SELECT @row_index:=0) ri
One more problem: The MAX(JaarWeek) gives me the max for every speler. It should be the max from the table (view) resultaten. I think I have to use a variable but don't know where and how (the row-index problem was solved thanks to Feherke)
Thanks in advance
Bauke
Is there a way to update another table with the results of this query?
The code should be (I think):
UPDATE standen
SET speler = speler, jaarweek = MAX(JaarWeek), stand = Stand
SELECT therealselect.*,@row_index:=@row_index+1 Stand from (
SELECT w_seizoen AS Seizoen
, MAX(w_datum)
, speler
, MAX(JaarWeek)
, COUNT(w_wnr) AS "Gespeeld"
, SUM(berpunten) AS "Tot. punten"
, SUM(berpunten)/COUNT(w_wnr) AS Winstperc
, ROUND(SUM(car)/SUM(w_brtn),4)- ROUND(temaken/25,4) AS Moyenne
, MAX(HSerie)/temaken AS "HSerie (%%)"
FROM resultaten
GROUP BY speler
ORDER BY Winstperc DESC, Moyenne DESC
) therealselect,(SELECT @row_index:=0) ri
One more problem: The MAX(JaarWeek) gives me the max for every speler. It should be the max from the table (view) resultaten. I think I have to use a variable but don't know where and how (the row-index problem was solved thanks to Feherke)
Thanks in advance
Bauke