选择具有最大值的行,与其他两个列相关
我有一个带有三列的桌子:区域,国家,计数。 我想将我的桌子减少到地区,国家和计数的行 - 该地区最大的数量。
例如,如果我有下表:
region | country | count
asia | jo | 12
asia | ir | 12
asia | il | 10
europe | fr | 8
europe | it | 2
我希望得到回报:
region | country | count
asia | jo | 12
asia | ir | 12
europe | fr | 8
I have a table with three columns: region, country, count.
I want to reduce my table to rows of region, country and count - where count is maximal among the region.
For example, if I have the following table:
region | country | count
asia | jo | 12
asia | ir | 12
asia | il | 10
europe | fr | 8
europe | it | 2
I'd expect to get in return:
region | country | count
asia | jo | 12
asia | ir | 12
europe | fr | 8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以以这种方式实现这一目标:首先,您需要按
region
字段对数据进行分组并获取最大值。然后在条件中执行一个简单的和
count
demo in sqldaddy.io
You can achieve this in this way: First you need to group the data by the
region
field and get the maximum value. Then execute a simpleIN
condition with fieldsregion
andcount
Demo in sqldaddy.io