P粉1584737802023-09-05 12:10:39
The columns/aggregation functions (MAX, COUNT, AVG, etc.) selected in the select query will be displayed as a table. In your query:
SELECT MAX(videogameid) FROM ....
Only the id of the video game with the largest value will be displayed. You only selected the videogameid with the largest value. In the second part of the query, videogameids that work with more than 5 developers are selected. Again, no selection headers are connected with the external SQL query.
Modified query:
SELECT videogameid,title FROM videogames WHERE videogameid IN (SELECT videogameid FROM workson GROUP BY videogameid HAVING COUNT(DISTINCT developerid)>5 );
This query shows videogameid and title with more than 5 developers
Another query:
SELECT COUNT(developerid) AS dev_count,videogameid FROM workson GROUP BY videogameid ORDER BY dev_count DESC LIMIT 1;
This shows the videogameid and number of developers for the selected video game that has the most developers. No title .
If we want to see the title:
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);
This query shows the titles and videogameids with the most developers.