Reputation: 45
I am new to SQL, this is what I am trying to figure out. Any help will be appreciated.
This is what I have as Input.
Number Start End Age
PRB1 1/2/2014 1/2/2014 0
PRB1 1/2/2014 1/3/2014 1
PRB1 1/3/2014 1/6/2014 1
PRB2 1/13/2014 1/14/2014 1
PRB3 1/9/2014 1/9/2014 0
PRB4 1/22/2014 1/22/2014 0
PRB4 1/25/2014 1/28/2014 1
This is the output I am expecting
Number Age
PRB1 2
PRB2 1
PRB3 0
PRB4 1
Upvotes: 1
Views: 77
Reputation: 13484
It will work
SELECT number,
Sum(age) AS Age
FROM tablename
GROUP BY number
Upvotes: 3
Reputation: 6590
Try this :
SELECT Number, SUM(Age) AS Age FROM Test GROUP BY Number
See GROUP BY
in more details :
http://www.w3schools.com/sql/sql_groupby.asp
Upvotes: 0
Reputation: 382
You need to use the Sum Aggregate function:
SELECT
NUMBER
,SUM(AGE) AS AGE
FROM
MYTABLE
GROUP BY
NUMBER
Upvotes: 1
Reputation: 14925
Just group by number, sum by age.
select number, sum(age) as total
from my_table
group by number
Upvotes: 1