【发布时间】:2017-06-24 14:45:30
【问题描述】:
比方说,我有下面这张表:
| Name | Voters
| George | 10
| Barack | 20
| Barack | 50
| Barack | 40
| Donald | 30
| Bill | 20
| George | 10
| Bill | 30
| Bill | 15
| Bill | 10
我想获得每个名称(或更少)的 2 个最大投票者的总和
| Name | Sum2BiggestVoters
| George | 20 (10 + 10)
| Donald | 30 (30)
| Bill | 20 (30 + 20; 10 and 15 are not considered not part of the 2 biggest numbers of voters for Bill)
| Barack | 90 (50 + 40; 20 is not considered here for the same reason as above)
看起来有点像这篇文章:How to get summation with count larger than certain amount,只是我使用的 SQLite 缺少row_number() over 功能以及partition by。
有什么想法吗?
【问题讨论】: