下表是相同的,但稍作修改:
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 | +--------+--------+--------+--------+
从本质上讲,我需要一个查询来选择参加过多次测试并且下次得分较低的人员的姓名。
例如,它将选择James但不选择Ryan,因为他第二次得分更高。
谢谢
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
sqlfiddle