I have a query that returns something like:
COMPANY | TOTAL
--------+------
A | 10
B | 15
C | 10
A | 5
A | 10
B | 5
D | 10
开发者_如何学编程Using this, I want to return results like:
COMPANY | TOTAL
--------+------
A | 25
B | 20
C | 10
D | 10
This has to be pretty simple, I just can't wrap my head around it.
Use this:
SELECT company, SUM(total)
FROM your_table
GROUP BY company
You can sort by sum appending
ORDER BY SUM(total) DESC
or by company
ORDER BY company
SELECT company, SUM(total)
FROM mytable
GROUP BY
company
精彩评论