Data stored in a database is often also useful for statistical
purposes. If you own a web-shop you want to be able to create a
report about turnover. You can get statistical information by
using GROUP BY, eg.
SELECT DATE_FORMAT(invoice.date, '%M') AS `month`, COUNT(*) AS `invoice_count`, SUM(`invoice`.`amount`) AS `turnover`
FROM `invoice`
WHERE `date` BETWEEN '2008-01-01' AND '2008-12-31'
GROUP BY MONTH(`invoice`.`date`)
month invoice_count turnover
January 84 9532.26
February 141 20857.61
March 91 10922.71
April 112 15044.48
May 101 9676.60
June 137 12860.88
July 281 34291.20
August 191 26377.66
September 103 16324.78
October 99 12873.23
If you are selling a wide variety of products, you might like to
see the turnover for each product category. You could do this
with a simple GROUP BY …
[Read more]