Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1SELECT COUNT(*) FROM students WHERE house = 'Red'; | ASUM cannot add up * (all fields). To count how many records, use COUNT(*); to total, SUM needs a numeric field. | |
| 2SELECT firstName, lastName FROM students WHERE points > 100 ORDER BY points DESC; | BLists the names of students with more than 100 points, highest points first | |
| 3'The total of' a numeric field for some records needs SUM with a WHERE condition | CSELECT SUM(quantity) FROM orders WHERE productId = 2; | |
| 4'In order of ... highest first' is written with ORDER BY and DESC at the end of the query | DAnswers 'how many records have house Red?' by counting the matching students | |
| 5SELECT firstName FROM students ORDER BY points DESC WHERE house = 'Blue'; | ESELECT name, price FROM products ORDER BY price DESC; | |
| 6SELECT SUM(*) FROM products WHERE stock = 0; | FORDER BY is placed before WHERE. WHERE must come first, then ORDER BY at the end. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
SELECT fields FROM table WHERE condition ORDER BY field DESC; — Turn a request into one SQL statement: pick fields after SELECT, the table after FROM, conditions in WHERE, sort with ORDER BY, and use SUM or COUNT for totals and how many.SELECT firstName, lastName FROM students
WHERE house = 'Red';SELECT COUNT(*) FROM students
WHERE yearLevel = 8;SELECT SUM(quantity) FROM orders
WHERE productId = 2;SELECT firstName, points FROM students
ORDER BY points DESC;SELECT name, price
FROM products
WHERE stock = 0;