2

I just made this post a little while ago: SQL query concerning the sum of occurrences for multiple rows

The table below is the same but with a slight modification:

                    Test

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

Essentially, I need a query to select the names of people who have taken multiple tests and gotten a lower score the next time.

For example, it would select James but not Ryan because he got a higher score the second time.

Thanks

1 Answer 1

2
SELECT DISTINCT a.name
FROM test AS a 
JOIN test AS b 
  ON a.name = b.name 
 AND a.date > b.date 
 AND a.score < b.score

SQL Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.