Course 9.3Lesson 3 of 3
In the examination you read a script and give its exact output, complete a script that has gaps, and find and correct the errors in a script. This lesson gives you a method for each task and practises it on the Tickets table.
Try the code and the simulations beside the lesson.
Examination questions on SQL come in three kinds.
All three use the same few keywords. Here is a method for each.
Work through the script in this order, whatever order it is written in.
AND both parts must be true, with OR at least one.Let us try it.
SELECT Day, Amount
FROM Tickets
WHERE Seats > 2 AND Show = 'Evening'
ORDER BY Amount DESC;The output:
Day Amount
Saturday 75
Sunday 45Write the output as a table, with the field names at the top. Keep the values exactly as they are in the table.
Read what the output must be, then fill each gap with one of the keywords or a field name.
SELECT ________(Seats)
FROM Tickets
WHERE Day = 'Friday' ________ Day = 'Sunday';The script must give the total seats sold on Friday and Sunday. A total is SUM. A sale cannot be on two days, so the days are joined with OR. The output is .
Check each part of the script against this list.
SELECT, FROM, WHERE, ORDER BY.AND or OR has its own field name.ASC or DESC comes after the field in ORDER BY.Example: SELECT SaleID Amount FROM Ticket WHERE Day = Saturday ORDER BY DESC Amount; has four errors. There is no comma between the fields. The table is Tickets. Saturday needs quotes. DESC must come after Amount.
The program runs a list of scripts on the Tickets table. For each one it prints the field names and the output, laid out like an examination answer. Write your own answer on paper first, then run it.
WHERE first and the SELECT last.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
SELECT SaleID FROM Tickets WHERE Day = 'Saturday' ORDER BY Seats ASC;.SELECT ________ FROM Tickets WHERE Show = 'Matinee'; so that it outputs .SELECT COUNT(*) FROM Tickets WHERE Seats > 2 AND < 5;.SELECT SUM(Amount) FROM Tickets WHERE Day = 'Sunday' OR Seats = 1; output?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.