Skip to content
Advertisement

Using select distinct with sum

I am not sure if what I want can be done but basically, I have a homework where I am supposed to come up with sql statements to filter through a database of a made up TCM company in any way. I wanted to filter branch to see which branch earns the most revenue.

but I am stuck here because I don’t know how to filter it.

The result is like so.

branch revenue

However, what I want is:

branch (sum of) revenue for each branch

but I can’t think of a way to make this work!

enter image description here

Advertisement

Answer

If I understood you problem correctly, you can use GROUP BY clause combined with SUM function to achieve what you want, like this:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement