For instance, if I want to display the sum of all invoices by year, I could write a request like:
Code: Select all
SELECT year(date) as y, SUM(price) as total
FROM invoices GROUP BY y ORDER BY y DESC
Code: Select all
SELECT year(date) as y, SUM(price) as total
FROM invoices GROUP BY y ORDER BY y DESC
Code: Select all
SELECT y,
total
FROM (
SELECT invoices_id,
Year(date) AS y,
Sum(price) AS total
FROM invoices
GROUP BY y, invoices_id
ORDER BY y DESC
) T