开发者

SQL limit total vs limit column

I have a table where there are multiple events that happen within multiple* years. I'd like to return 5 total results (LIMIT 5), however I just wan't to return one of the events per year. How would this be done?

database table
2001 - something happened
1998 -开发者_JS百科 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


basically you need to group your results by year, but we need to know whick event you need so you can set aggregate function.

UPDATE
so ....

SELECT event FROM table GROUP BY year ORDER BY id LIMIT 5

but, in case of year 2001, which one you need?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜