【发布时间】:2021-08-08 13:10:58
【问题描述】:
我有一个如下的 event_table。
city country event date
london UK Soccer 8/20/2010
toronto CA Basketball 8/12/2011
newyork US Basketball 8/21/2012
LA US Basketball 8/30/2013
.....
我需要获取所有符合这些条件的字段:
- 仅 30 个条目
- event = "棒球"
- 按日期排序
- 不同的国家“美国”。
我在下面尝试过:
select distinct on country *
from event_table
where event="Basketball"
order by date Dec limit 20;
及以下:
select *
from event_table
where event="Basketball"
order by date Dec limit 20
group by country;
但没有工作。提前感谢您的帮助。
【问题讨论】:
-
不同国家是什么意思?只有一个国家?
-
是的,我每次只想回一个国家。
-
你的最后一条 SQL 语句对我来说看起来没问题,除了我记得的限制应该在语句的末尾。结果有什么问题?
-
哪个mysql版本?
-
select * from event_table where event="Basketball" group by
countryorder bydatedesc limit 20;