Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

MySQL SELECT dari beberapa tabel, beberapa GROUP BY dan 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

Hasil diverifikasi di SQL Fiddle .




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. com.zaxxer.hikari.pool.PoolInitializationException:Pengecualian selama inisialisasi kumpulan

  2. apa perbedaan antara GROUP BY dan ORDER BY di sql

  3. Pengasinan hash saya dengan PHP dan MySQL

  4. Setel nilai AUTOINCREMENT di tabel Django

  5. Pembuatan MySQL ke Excel menggunakan PHP