Skip to content
Advertisement

Grouping Totals With SQL Query

Here’s the situation:

I have a table that has two data columns:

Number | Value
     0 |    11
     0 |    10
     0 |    12
     1 |    10
     1 |    10
     1 |    11
     2 |    11
       .
       .
       .

And so on…

I would like to create a query that presents the totals for the different numbers separately, so it would end up being like so:

Number | Total
     0 |    33
     1 |    31
     2 |    11
       .
       .
       .

I’ve tried applying a simple SUM(Value) into my Query, but I can’t seem to get it right.

Any help would be greatly appreciated.

Advertisement

Answer

select number , sum(value) as "total" from tablename
group by Number 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement