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。
#