Files
me50/6.sql
2026-04-28 15:45:13 +02:00

15 lines
564 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- write a SQL query to return the top 5 teams, sorted by the total number of hits by players in 2001.
-- Call the column representing total hits by players in 2001 “total hits”.
-- Sort by total hits, highest to lowest.
-- Your query should return two columns, one for the teams names and one for their total hits in 2001.
SELECT
t."name",
SUM(perf."H") AS "total hits"
FROM "teams" AS t
JOIN "performances" AS perf
ON perf."team_id" = t."id"
WHERE perf."year" = '2001'
GROUP BY t."id", t."name"
ORDER BY "total hits" DESC
LIMIT 5;