MySQL Gruppierungsproblem

qwerty12309

Grünschnabel
Hallo, ich versuche mein Problem mal zu beschreiben:
Hier ein Tabellenausschnitt:
Jeder Datensatz ist ein nach Plattformen aufgefaechertes Spiel.

Code:
mysql> select * from gnl_gamesearch2 where game_id = 5605;                                                                                                   
+---------+---------------------------+-------------+------------+-----------------+--------+----------+----------+------------+
| game_id | title                     | platform_id | release    | expandedRelease | rating | genre_id | gamepage | doc_review |
+---------+---------------------------+-------------+------------+-----------------+--------+----------+----------+------------+
|    5605 | Pro Evolution Soccer 2008 |        3199 | 1193263200 | 25/10/2007      |   NULL |     1070 |        1 |       NULL |
|    5605 | Pro Evolution Soccer 2008 |        3143 | 1193263200 | 25/10/2007      |   NULL |     1070 |        1 |       NULL |
|    5605 | Pro Evolution Soccer 2008 |        2716 | 1193871600 | November 2007   |   NULL |     1070 |        1 |       NULL |
|    5605 | Pro Evolution Soccer 2008 |        2287 | 1193871600 | November 2007   |   NULL |     1070 |        1 |       NULL |
|    5605 | Pro Evolution Soccer 2008 |        3203 | 1193263200 | 25/10/2007      |   NULL |     1070 |        1 |       NULL |
|    5605 | Pro Evolution Soccer 2008 |        2568 | 1193263200 | 25/10/2007      |      8 |     1070 |        1 |      42401 |
+---------+---------------------------+-------------+------------+-----------------+--------+----------+----------+------------+
Im Query, der die Daten fuer die Seite aus der Datenbank holt, werden die Spiel/Plattform-Kombinationen nach release-Datum gruppiert, sodass man eine Uebersicht hat, welches Spiel wann erscheint.

Code:
SELECT ggs.game_id, GROUP_CONCAT( DISTINCT ggs.platform_id ) AS curPlatforms, ggs.`release`, ggs.title, ggs.rating, GROUP_CONCAT( DISTINCT ggs2.platform_id ) AS allPlatformIds, ggs.doc_review, IF(ggs.rating IS NOT NULL, ggs.rating, IF( ggs.`release` IS NOT NULL AND ggs.`release` > 1193236878, ggs.`release`, 0)) AS rating_release FROM gnl_gamesearch2 ggs JOIN gnl_gamesearch2 ggs2 ON ( ggs.game_id = ggs2.game_id ) WHERE ggs.game_id = 5605 GROUP BY ggs.game_id, ggs.`release` ORDER BY ggs.`release`;
+---------+---------------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
| game_id | curPlatforms        | release    | title                     | rating | allPlatformIds                | doc_review | rating_release |
+---------+---------------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
|    5605 | 3199,2568,3203,3143 | 1193263200 | Pro Evolution Soccer 2008 |   NULL | 3199,3203,2287,2568,2716,3143 |       NULL |     1193263200 |
|    5605 | 2287,2716           | 1193871600 | Pro Evolution Soccer 2008 |   NULL | 2716,3143,3199,2568,3203,2287 |       NULL |     1193871600 |
+---------+---------------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
Nun werden aber nur NULL-Werte anstatt eines Ratings angezeigt. Wenn ich es nach 'rating' gruppiere, bekomme ich zwei Eintraege zu einem Release-Datum 25/10/2007 (und einen zum Datum November 2007):

Code:
SELECT ggs.game_id, GROUP_CONCAT( DISTINCT ggs.platform_id ) AS curPlatforms, ggs.`release`, ggs.title, ggs.rating, GROUP_CONCAT( DISTINCT ggs2.platform_id ) AS allPlatformIds, ggs.doc_review, IF(ggs.rating IS NOT NULL, ggs.rating, IF( ggs.`release` IS NOT NULL AND ggs.`release` > 1193236878, ggs.`release`, 0)) AS rating_release FROM gnl_gamesearch2 ggs JOIN gnl_gamesearch2 ggs2 ON ( ggs.game_id = ggs2.game_id ) WHERE ggs.game_id = 5605 GROUP BY ggs.game_id, ggs.rating ORDER BY ggs.`release`;
+---------+----------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
| game_id | curPlatforms   | release    | title                     | rating | allPlatformIds                | doc_review | rating_release |
+---------+----------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
|    5605 | 3199,3143,3203 | 1193263200 | Pro Evolution Soccer 2008 |   NULL | 3199,3143,2716,2287,3203,2568 |       NULL |     1193263200 |
|    5605 | 2568           | 1193263200 | Pro Evolution Soccer 2008 |      8 | 3199,3143,2716,2287,3203,2568 |      42401 |              8 |
|    5605 | 2716,2287      | 1193871600 | Pro Evolution Soccer 2008 |   NULL | 3199,3143,2716,2287,3203,2568 |       NULL |     1193871600 |
+---------+----------------+------------+---------------------------+--------+-------------------------------+------------+----------------+
Ich moechte aber nur den mittleren Datensatz mit rating=8 statt den oberen Datensatz. (Der untere Datensatz ist fuer ein anderes Datum und soll deshalb auch auf der Resultatseite erscheinen.)
Was muss an dem Query veraendert werden? Ich habe es schon mit Sortierungen versucht, ohne Erfolg.
Ich hoffe sehr auf eure Hilfe
 

Neue Beiträge

Zurück