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

Grupper, sorter og tæl i en enkelt forespørgsel

Bare mit gæt på, hvad du beder om http://sqlfiddle.com/#!9/ e9206/16

fordi det giver det ønskede resultat:

SELECT A.family, C.NbrFamily,A.sub_family,B.NbrSubFamily,A.name,COUNT(A.Name) FROM commodities as A LEFT JOIN ( SELECT family,sub_family,COUNT(Name) AS NbrSubFamily FROM commodities GROUP BY family,sub_family ) B ON A.sub_family = B.sub_family AND A.family = B.family LEFT JOIN ( SELECT family,COUNT(Name) AS NbrFamily FROM commodities GROUP BY family ) C ON A.family = C.family GROUP BY A.family,A.sub_family,A.name ORDER BY A.id


  1. mysql til php til xml viser blank alder

  2. Hvorfor vises Unicode-tegn korrekt i databasen, men som ? når den udskrives i Java via Hibernate?

  3. MySQL Tutorial - En begyndervejledning til at lære MySQL

  4. MySQL - vælg data fra databasen mellem to datoer