Mysql SQL限制总计与限制列
我有一个表格,其中有多个事件在多个*年内发生。我想返回5个总结果(限制为5个),但我不想每年返回一个事件。如何做到这一点Mysql SQL限制总计与限制列,mysql,sql,Mysql,Sql,我有一个表格,其中有多个事件在多个*年内发生。我想返回5个总结果(限制为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 coo
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
基本上,您需要按年度对结果进行分组,但我们需要知道您需要哪些事件,以便您可以设置聚合函数 更新
所以
但是,在2001年的情况下,您需要哪一个?“…但是我不想每年返回一个事件…”哪一个事件?对我来说,听起来像是一个分组(eventdate),但是谁能说没有看到表schemayear只是一个例子,我可能需要它是一个id或其他什么。我更新了我的帖子,现在它更有意义了吗?所有事件,事件是一个不好的词吗?我的字面意思是那年发生的一件事。我更新了我的帖子,现在更有意义了吗?谢谢你告诉我关于
groupby
SELECT event FROM table GROUP BY year ORDER BY id LIMIT 5