简体   繁体   中英

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.

select number , sum(value) as "total" from tablename
group by Number 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM