sql >> Databáze >  >> RDS >> Mysql

MySQL SELECT z více tabulek, více GROUP BY a group_concat?

SELECT Leaderboard.Name,
  (SELECT Actions.Action
   FROM Actions
   WHERE Actions.Name = Leaderboard.Name
     AND Actions.Action LIKE 'Ate%'
   ORDER BY Time DESC
   LIMIT 1
  ) AS Latest_Action,
  GROUP_CONCAT(Items.Item
               ORDER BY Items.Time DESC
               SEPARATOR ', '
              ) AS Items
FROM Leaderboard
     LEFT JOIN Items ON Leaderboard.Name = Items.Name
GROUP BY Leaderboard.Name
HAVING Latest_Action IS NOT NULL
ORDER BY Leaderboard.Score DESC

Výsledek ověřen v SQL Fiddle .




  1. Jak získat přístup k prvkům pole

  2. mysql Neplatný počet sloupců ve vstupu CSV při importu souboru csv

  3. Python zkopíruje tabulku MySQL do SQLite3

  4. Konec podpory pro SQL Server 2008 a 2008 R2