Do Tutorials 0–3 from the SQLZoo Tutorial; you can do the quizzes if you'd like to reinforce your knowledge. Optionally, do Tutorials 4–7, if you want to try the optional problems below. (Any substantive knowledge of SQL demands the techniques used for the optional problems, so you should do them unless you really struggle with the required problems.)
Using this SQL Fiddle practice database on Roman gladiators, answer the questions. You'll need to type your SELECT queries at the bottom of the script, where it says 'CREATE YOUR OWN QUERIES BELOW'. If you decide to run more than one query at a time, be sure to finish each query with a semicolon! (N.B. Database schema and sample data created with the rather entertaining assistance of ChatGPT; I've copied our conversation into a document since evidently talking about killing gladiators is a potential violation of terms of service and thus the chat can't be shared...)
Note: You may find it convenient to use short aliases for the tables, to avoid having to type long table names. You can supply any alias you like directly after the name of the table in your SELECT statement and then reuse that alias elsewhere, even earlier in the statement. For example, here I use ts as shorthand for TrainingSchools and g as shorthand for Gladiators (try running this query in the SQL Fiddle and see what happens!):
SELECT g.Name AS GladiatorName,
ts.Name AS LudusName
FROM Gladiators g
JOIN TrainingSchools ts
ON g.TrainingSchoolID = ts.SchoolID;
Hand in: A Word file (.doc or .docx) with the SQL query and result table for each question. You can download a Word document with just the questions here. You can copy and paste your query and the result table from the SQL Fiddle into the Word document.
Required (Straightforward)
These use the tables gladiator_list and match_list. Before starting to write your queries, you'll want to see what's in each table by running SELECT * FROM gladiator_list; and SELECT * FROM match_list;.
Required (Slightly Harder)
These use the tables gladiator_list and match_list.
LIMIT 1 at the end of the query.)MatchID, WinnerID, and LoserID; return your results in chronological order. (To start with the largest number, add DESC at the end of the ORDER BY clause.)FALSE and 1 is the same as TRUE).DeathDate and DateOfBirth. (You can use ColumnA - ColumnB both in the SELECT statement [give it the alias 'Age' using AS Age right after the formula] and in the WHERE clause.)Optional (More Challenging)
These exercises may use GROUP BY, JOIN, and the aggregate function COUNT(). You should use (some of) the tables Owners, Gladiators, TrainingSchools, TypesOfGladiators, and Matches. Remember to check the column names of each table by doing SELECT * FROM Table before you try working with that table.
JOIN, list just the names of the gladiators and the names of their owners.Optional (Most Challenging)
These exercises may use GROUP BY, JOIN, and HAVING, as well as some aggregate functions such as COUNT() or MAX()/MIN(). You should use the tables Owners, Gladiators, TrainingSchools, TypesOfGladiators, and Matches. Remember to check the column names of each table by doing SELECT * FROM Table before you try working with that table.
TypeName and the count of that TypeName. Do not use LIMIT.)LIMIT; you will need to use a subquery (i.e., SELECT within SELECT) for this.Owners.Name column [you may rename it if you like] and the count of their gladiators' wins, as NumWins.)