I'm trying to execute a correlated sub-query in the SELECT clause of a MySQL query. How do I use the value of a row in another column inside the WHERE clause of my subquery?
I've been referencing the "Correlated Sub-Query Example" section of this webpage, but for some reason my query is not working the same.
Here is my code:
SELECT Year,
     ( SELECT COUNT(*)
       FROM systems
       WHERE SYSTEMTYPE = 'handheld' AND Year = sys.Year
     ) as handheld,
     ( SELECT COUNT(*)
       FROM systems
       WHERE SYSTEMTYPE = 'console' AND Year = sys.Year
     ) as console,
FROM systems as sys
WHERE Year IS NOT NULL
Basically, I'm trying to create a table that shows how many systems of each type were created for each year. When I run that query in MySQL Workbench it runs until the database connection expires. I can't see how this query is much different than the one on the website I am referencing.
Any help would be greatly appreciated! If it seems there is a better way I could go about this, I am open to those ideas as well. Thank you!
 
     
     
    