如何找到拥有最多开发人员的视频游戏名称? (SQL查询)
假设我们有 3 张表,分别是 视频游戏、开发商、workson。
在视频游戏表下,我们有诸如
- videogameid (PK)
- 标题
- 年份
- 流派之类
的属性然后对于开发人员我们有
- developerid (PK)
- 名称
- 性别
然后对于工作表
- videogameid(PK & FK)
- Developerid (PK & FK)
我的尝试代码:
SELECT MAX(videogameid)
FROM
(SELECT videogameid
FROM workson
GROUP BY videogameid
HAVING COUNT(DISTINCT developerid)>5
)videogames_with_most_developers;
但是,我未能检索到带有标题的答案(主要是因为我没有选择标题),但那是因为我似乎无法建立连接。
编辑:所以我们有一些样本数据 我们哪里有桌上电子游戏 插入视频游戏(视频游戏 ID、标题、年份、类型)
价值观(111,魔兽世界,2004,MMORPG); 插入视频游戏(视频游戏 ID、标题、年份、类型) 价值观(112,星际争霸 2,2008,RTS);
对于表开发人员 我们有 插入开发人员(开发人员 ID、性别、姓名) 价值观(98734,M,约翰逊); 插入开发人员(开发人员 ID、性别、姓名) 价值观(98735,F,里贾纳); 插入开发人员(开发人员 ID、性别、姓名) 价值观(98736,M,拉马尔);
对于工作台 INSERT INTO(videogameid、developerid) 值 (111, 98734); INSERT INTO(videogameid、developerid) 价值观(111,98735); INSERT INTO(videogameid、developerid) 值(112,98736);
预期输出应该是标题“魔兽世界”,因为它的最大开发人员数量为 2,而“星际争霸”等标题没有最大开发人员数量(如示例数据所示)
Let's say that we have 3 tables which are
videogames, developers, workson.
Under the videogames table, we have attributes such as
- videogameid (PK)
- title
- year
- genre
Then for developers we have
- developerid (PK)
- name
- gender
Then for the workson table
- videogameid(PK & FK )
- developerid (PK & FK )
My attempt at the code:
SELECT MAX(videogameid)
FROM
(SELECT videogameid
FROM workson
GROUP BY videogameid
HAVING COUNT(DISTINCT developerid)>5
)videogames_with_most_developers;
However, I have failed to retrieve the answer with the title ( mainly because I did not select the title) but that's because I can't seem to make the connection.
EDIT: So we have some sample data
where for table videogames we have
INSERT INTO videogames (videogameid, title,year,genre)
VALUES (111,World of Warcraft ,2004, MMORPG);
INSERT INTO videogames (videogameid, title,year,genre)
VALUES (112,Starcraft 2 ,2008, RTS);
For the table developers
we have
INSERT INTO developers( developerid, gender, name)
VALUES ( 98734, M, Johnson);
INSERT INTO developers( developerid, gender, name)
VALUES ( 98735, F, Regina);
INSERT INTO developers( developerid, gender, name)
VALUES (98736, M , Lamar);
For the table workson
INSERT INTO (videogameid, developerid)
VALUES (111, 98734);
INSERT INTO (videogameid, developerid)
VALUES (111,98735);
INSERT INTO (videogameid, developerid)
Values(112,98736);
The expected output should be the title 'World of Warcraft' because it has the maximum number of directors working on it which is 2 whereas title such as 'Starcraft' does not have the maximum number of developers working on it as seen in this sample data
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在选择查询中选择的列/聚合函数(MAX、COUNT、AVG 等)将显示为表格。
在您的查询中:
仅显示值最大的视频游戏的 id。您只需选择具有最大值的 videogameid。在查询的第二部分中,选择为超过 5 个开发人员工作的 videogameid。同样,没有选择连接到外部 SQL 查询的标题。
查询的修改版本:
此查询显示超过 5 个开发者的 videogameid 和标题
另一个查询:
这显示 videogameid以及参与选定视频游戏的开发者数量以及参与该游戏的最大开发者数量。没有标题。
如果我们想查看标题:
此查询显示标题和 videogameid 以及最大数量的开发人员。
Which columns/aggregate function(MAX,COUNT,AVG etc.) you select in the select query will be shown as a table.
In your query:
only the id of the video game with the largest value will be displayed. You just select the videogameid with the greatest value.In the second part of the query select videogameid that work more than 5 developers.Again there is no title selected to connect to the outer sql query.
Modified version of your query:
This query shows videogameid and title with more than 5 developers
Another query:
this shows videogameid and number of developers that work on selected video game with the maximum amount of developers working on it.There is no title.
If we want to see the title :
This query shows title and videogameid with the maximum amount of developers working on it.