sampleton
sampleton

Reputation: 55

SQL query concerning the sum of occurrences for multiple rows

I need a little bit of help in getting this SQL query to work. Say I have a table like this:

                Test

    +--------+--------+--------+
    |  Name  |  Date  |Location|
    +--------+--------+--------+
    | Steven |03-05-12| 120000 |
    +--------+--------+--------+
    | James  |04-09-11| 110000 |
    +--------+--------+--------+
    | James  |06-22-11| 110000 |
    +--------+--------+--------+
    |  Ryan  |10-11-13| 250000 |
    +--------+--------+--------+
    |  Ryan  |12-19-13| 180000 |
    +--------+--------+--------+

I need to find the name of every individual who has taken a "test" more than one time, but at the same location.

For example, James would be selected because he took two tests at location 110000, but Ryan would not be selected because he took his two tests at two different locations.

Thanks!

Upvotes: 0

Views: 76

Answers (1)

Brian DeMilia
Brian DeMilia

Reputation: 13248

select name
  from tbl
 group by name,
          location
having count(*) > 1

Upvotes: 3

Related Questions