Way to find video games with the most developer involvement (using SQL query)
P粉768045522
2023-09-04 16:18:24
<p>Suppose we have 3 tables, namely videogames, developers and workson. </p>
<p>In the videogames table, we have the following attributes: </p>
<ul>
<li>videogameid (primary key)</li>
<li>Title</li>
<li>Year</li>
<li>genre</li>
</ul>
<p>Then in the developers table, we have: </p>
<ul>
<li>developerid (primary key)</li>
<li>Name</li>
<li>gender</li>
</ul>
<p>Then in the workson table, we have: </p>
<ul>
<li>videogameid (primary and foreign keys)</li>
<li>developerid (primary and foreign keys)</li>
</ul>
<p>My code attempt:</p>
<pre class="brush:php;toolbar:false;">SELECT MAX(videogameid)
FROM
(SELECT videogameid
FROM workson
GROUP BY videogameid
HAVING COUNT(DISTINCT developerid)>5
)videogames_with_most_developers;</pre>
<p>However, I failed to retrieve answers with titles (mainly because I didn't select a title), but that's because I can't seem to make the connection. </p>
<p>Edit: We have some sample data, in the videogames table: </p>
<p>Insert video game (videogameid, title, year, type)</p><p>
VALUES (111,'World of Warcraft',2004,'MMORPG');
Insert video game (video game id, title, year, type)
VALUES (112,'StarCraft II',2008,'RTS');</p>
<p>The developers table contains: </p>
<p>Insert developer (developer ID, gender, name)
value(98734,'M','Johnson');
Insert developer (developer ID, gender, name)
value(98735,"F","Regina");
Insert developer (developer ID, gender, name)
value(98736,"M","Lamar"); </p>
<p>The workson table contains: </p>
<p>Insert workson(videogameid,developerid)
value (111, 98734);
insert workson(videogameid,developerid)
Values (111, 98735);
insert workson(videogameid,developerid)
Value (112, 98736);</p>
<p>The expected output should be the one titled 'World of Warcraft' because it has the most directors working on this project with a count of 2, while the project titled 'Starcraft 2' does not have the most developers in this sample data . </p>
The columns/aggregation functions (MAX, COUNT, AVG, etc.) selected in the select query will be displayed as a table. In your query:
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:
This query shows videogameid and title with more than 5 developers
Another query:
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:
This query shows the titles and videogameids with the most developers.