ssss
ssss

Reputation: 573

Displaying the combined data in sql

given a table:

my_table:
**PERSON**  **AGE**
  person1     20
  person1     20
  person2     30
  person2     30

how can i display the data where person = person and age = age, i.e:

person1  40
person2  60

?

Upvotes: 0

Views: 27

Answers (1)

GolezTrol
GolezTrol

Reputation: 116190

You can group by person name, and sum the age, although it seems a bit odd to do that. If two people say I'm 20, then it doesn't make me 40. :)

SELECT   person,
         SUM(age) as age
FROM     my_table
GROUP BY person

Upvotes: 1

Related Questions