MySQL Forums
Forum List  »  German

Re: UPDATE in Kombination mit ORDER BY sehr langsam
Posted by: Thomas Wiedmann
Date: August 08, 2012 09:50AM

Hallo Tobias,

das Ergebnis des UPDATE stimmt meiner Meinung nach nicht, wenn mehrere Spieler identische siege, unentschieden und niederlagen haben. Dann sollten alle die selbe position haben. Der UPDATE erzeugt aber unterschiedliche Positionen.

INSERT INTO highscores VALUES
( 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1),
( 2, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1),
( 3, 6, 3, 1, 1, 1, 1, 1, 1, 1, 1);

SELECT spielerid, position, siege, unentschieden, niederlagen
  FROM highscores
ORDER BY position;
+-----------+----------+-------+---------------+-------------+
| spielerid | position | siege | unentschieden | niederlagen |
+-----------+----------+-------+---------------+-------------+
|         4 |        1 |     1 |             1 |           1 |
|         5 |        1 |     1 |             1 |           1 |
|         6 |        1 |     1 |             1 |           1 |
+-----------+----------+-------+---------------+-------------+
3 rows in set (0.00 sec)


SET @X := 0;
UPDATE highscores 
   SET positionAlt = position, 
       position = (SELECT @x := @x + 1) 
 WHERE spielmodus=1 
ORDER BY siege DESC, niederlagen ASC, unentschieden DESC;

SELECT spielerid, position, siege, unentschieden, niederlagen
  FROM highscores
ORDER BY position;
+-----------+----------+-------+---------------+-------------+
| spielerid | position | siege | unentschieden | niederlagen |
+-----------+----------+-------+---------------+-------------+
|         4 |        1 |     1 |             1 |           1 |
|         5 |        2 |     1 |             1 |           1 |
|         6 |        3 |     1 |             1 |           1 |
+-----------+----------+-------+---------------+-------------+
3 rows in set (0.00 sec)

mysql>

Grüße
Thomas

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.