2010-02-02 6 views

Répondre

8

Cela devrait faire l'affaire:

SELECT c.ID, c.Name, count(i.ID) 
FROM Categories c 
LEFT JOIN Items i on (c.ID=i.CategoryID) 
GROUP BY c.ID 
ORDER BY count(i.ID) 
1
SELECT 
    CategoryID, count(*) 
FROM 
    items 
GROUP BY 
    CategoryID 
ORDER BY 
    2 DESC 

Vous pouvez ensuite vous joindre à des catégories pour obtenir leur nom.