P粉1584737802023-09-05 12:10:39
在选择查询中选择的列/聚合函数(MAX、COUNT、AVG等)将显示为一个表格。 在你的查询中:
SELECT MAX(videogameid) FROM ....
只会显示具有最大值的视频游戏的id。你只选择了具有最大值的videogameid。在查询的第二部分中,选择了与5个以上开发人员合作的videogameid。同样,没有选择标题与外部SQL查询连接。
修改后的查询:
SELECT videogameid,title FROM videogames WHERE videogameid IN (SELECT videogameid FROM workson GROUP BY videogameid HAVING COUNT(DISTINCT developerid)>5 );
此查询显示具有5个以上开发人员的videogameid和标题
另一个查询:
SELECT COUNT(developerid) AS dev_count,videogameid FROM workson GROUP BY videogameid ORDER BY dev_count DESC LIMIT 1;
这显示了具有最多开发人员的选定视频游戏的videogameid和开发人员数量。没有标题。
如果我们想要看到标题:
SELECT videogameid,title FROM videogames WHERE videogameid IN (SELECT videogameid FROM (SELECT COUNT(developerid) AS count,videogameid FROM workson GROUP BY videogameid ORDER BY COUNT(developerid) DESC LIMIT 1) AS T);
此查询显示具有最多开发人员的标题和videogameid。