【发布时间】:2020-06-27 21:39:26
【问题描述】:
我有这张桌子。
id country col1 col2 col3
1 country1 1 2 3
2 country1 2 2 1
3 country1 1 3 2
4 country2 3 2 2
5 country2 3 3 3
6 country3 3 2 2
7 country3 3 1 1
我正在尝试输出每个不同国家/地区的最后一行。
id country col1 col2 col3
3 country1 1 3 2
5 country2 3 3 3
7 country3 3 1 1
我尝试了各种解决方案,例如:
select distinct(country), col1, col2, col3 from ( SELECT country, col1, col2, col3 from tablename order by id DESC) a limit 1
但是,我无法获得所需的输出。
如何获取每个国家/地区的最新不同行?
谢谢!
【问题讨论】:
标签: mysql sql select subquery greatest-n-per-group