'I want to find which publisher had the highest global sales between the specific dates. Am I doing this correctly?

Table Column Layout

So far i've got:

SELECT Publisher, MAX(Global_Sales) AS Most_Sales
FROM Vgsales
WHERE Year BETWEEN 1980 AND 1990;

but not sure whether this is correct or not.



Solution 1:[1]

Among the countless ways, you can use something like:

WITH cte AS (
  SELECT SUM(global_sales) total, publisher FROM VGSALES
  WHERE year BETWEEN 1999 AND 2000
  GROUP BY publisher
)
SELECT * FROM cte WHERE total = (SELECT MAX(total) FROM cte)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jassis