我有一张表,其中有多个事件发生在多个*年内。我想返回5个总结果(LIMIT 5),但是我不想每年返回一个事件。怎么会这样做?
database table
2001 - something happened
1998 - something else happened
2001 - something more exciting happened
2003 - something friggen cool happened
1998 - something else happened the coolest thing ever
query returns
2001 - something happened
1998 - something else happened
2003 - something friggen cool happened
答案 0 :(得分:2)
基本上您需要按年度对结果进行分组,但我们需要知道您需要的事件,以便设置聚合函数。
<强>更新强>
所以......
SELECT event FROM table GROUP BY year ORDER BY id LIMIT 5
但是,如果是2001年,你需要哪一个?