帮忙sql查询连接?
我有两个表,类型为(类型,玩家ID)和玩家(玩家ID,日期) 我必须查明每年有多少场比赛最佳球员是由哪种类型的球员获得的?
例如,表格应该是这样的:
year type noofawards
2011 batsmen 3
2011 bowler 5
2010 batsmen 2
我可以获得每年获得的奖项总数,但无法按类型将它们分开,所以我得到的是
year noofawards
2011 3
select year , count(year) as "Number of awards"
from
(
select to_char(p.date,'YYYY') as year
from player p, type t
where p.playerid = t.playerid
)
group by year
order by year;
我应该做什么?
i have two tables with type(type,playerid) and player(playerid,date)
i have to find out for each year how many man of the match awards were won by which type of player ?
eg the table should be like
year type noofawards
2011 batsmen 3
2011 bowler 5
2010 batsmen 2
i can get the total number of awards won each year but cannot segregate them on type so what i get is
year noofawards
2011 3
select year , count(year) as "Number of awards"
from
(
select to_char(p.date,'YYYY') as year
from player p, type t
where p.playerid = t.playerid
)
group by year
order by year;
what should i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过以下操作:
Did you try the following:
由于这是家庭作业的尖叫声,我只会给出提示。
您不需要使用子查询,并且需要在查询中的某个时刻实际选择“类型”列。
Since this screams of homework, i will just give hints.
you don't need to use an subqueries and you need to actually select the Type column at some point in your query.
只需使用:
YEAR()
或类似名称)从日期中提取年份。JOIN
语法,而不是使用WHERE
的隐式连接。像这样的东西:
Just use:
YEAR()
or similar name) to extract year from a date.date
is not a good idea.JOIN
syntax rather the implicit join withWHERE
.Something like:
这应该有效:
This should work: