PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

SQL:come salvare l'ordine nella query sql?

Invece di subquery usa join . Prova questo.

SELECT p.*
FROM   person p
       JOIN (SELECT p.id,
                    Count(p.NAME)cnt
             FROM   car c
                    JOIN person p
                      ON c.person_id = p.id
             GROUP  BY p.id) b
         ON p.id = b.id
ORDER  BY cnt ASC