-- Query 23

SELECT
    facture.numfacture AS 'facture',
    DATE_FORMAT(facture.datefacture, "%d/%m/%y") AS 'date',
    COUNT(comprend.numcons) AS 'nb conso'
FROM comprend
INNER JOIN facture ON comprend.numfacture = facture.numfacture
WHERE facture.datefacture < "20060222"
GROUP BY facture.numfacture
HAVING `nb conso` > 3
ORDER BY SUM(comprend.numcons) DESC;

/* == RESULT ==
"Facture","Date","Nb conso"
1003,"04/12/05",6
1203,"21/02/06",5
1103,"21/01/06",5
1200,"21/02/06",4
*/
