sql >> Database teknologi >  >> RDS >> Mysql

MySQL SELECT fra flere tabeller, flere GROUP BY og 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

Resultat bekræftet i SQL Fiddle .




  1. Hvordan bruger man If Then Else i en MySQL-opdateringsforespørgsel?

  2. hente specialtegn fra mysql database, php

  3. Sådan finder du ASCII-koden for en given karakter i MySQL

  4. mysql feltnavn fra variabel