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

MySQL Multiple Counts i Single Query

Brug:

   SELECT tm.*, 
          x.listcount, 
          y.uploadcount 
     FROM $tbl_members tm 
LEFT JOIN (SELECT tl.username,
                  COUNT(tl.listname) AS listcount
             FROM $tbl_list tl
         GROUP BY tl.username) x ON x.username = tm.username
LEFT JOIN (SELECT tu.username,
                  COUNT(tu.id) AS uploadcount
             FROM $tbl_uploads tu
         GROUP BY tu.username) y ON y.username = tm.username
 GROUP BY tm.username 
 ORDER BY tm.lastname, tm.firstname



  1. Konverter en mySQL-dato til Javascript-dato

  2. Oracle svarende til Postgres' DISTINCT ON?

  3. SQL Server-markørtyper - Hvad er forskellen mellem LOKAL OG GLOBAL markør | SQL Server Tutorial / TSQL Tutorial

  4. Sådan importeres csv-filer valgt af brugeren til databasen