我有一个表可以说排名信息具有我需要找到最选民在每年的Oracle SQL查询
username mvid votedate
john 1 23-sep-90
john 2 23-sep-90
smith 1 23-sep-90
john 3 24-oct-91
smith 3 24-oct-91
smith 4 25-dec-91
smith 5 25-dec-91
我需要写的SQLDeveloper一个SQL查询(甲骨文),它会给我的成员谁在每年得到最多的选票。输出应该是用户名,年份,每年的总票数。 让我们考虑一下上面的例子: 我需要这样的输出。
username year number_Of_Votes
john 1990 2
smith 1991 3
因为在1990年约翰击败史密斯1投票,而在1991年史密斯击败约翰2票。
我达到了统计所有选票的程度,但我无法获得一年中的最大票数。
这是我做了什么:
select r1.username,
Extract(year from r1.votedate)"Year",
count(username)
from rankinginfo r1
where Extract(year from r1.votedate) is not null
group by Extract(year from r1.votedate),
r1.username;
order by Extract(year from r1.votedate),
username;
如果由于某种原因想要删除自己的帖子,请点击帖子下方的“删除”按钮,而不是删除帖子的内容。谢谢。 – 2013-05-19 06:15:51
我回滚了你的编辑。如果您想删除该问题,请这样做。删除内容不是StackOverflow的工作方式。如果你需要更多的信息,你应该查看[faq]和[about]页面,或者选择[meta]。 – 2013-05-19 06:20:05