Complete the code to select all columns from a derived table named 'sub'.
SELECT [1] FROM (SELECT id, name FROM users) AS sub;Using * selects all columns from the derived table sub.
Complete the code to count the number of users in the derived table.
SELECT COUNT([1]) FROM (SELECT id FROM users) AS user_count;Counting id counts the number of rows in the derived table.
Fix the error in the code by completing the alias for the derived table.
SELECT sub.id FROM (SELECT id FROM users) [1];The AS keyword is used to alias the derived table.
Fill both blanks to select user names and their total orders from a derived table.
SELECT [1], orders FROM (SELECT user_id, COUNT(*) [2] orders FROM orders GROUP BY user_id) AS order_summary JOIN users ON users.id = order_summary.user_id;
users.name selects the user name, and AS aliases the count as orders.
Fill all three blanks to create a derived table that calculates average scores and select students with average above 80.
SELECT [1], avg_score FROM (SELECT student_id, AVG(score) [2] avg_score FROM scores GROUP BY student_id) [3] WHERE avg_score > 80;
student_id is selected, AS aliases the average score, and high_achievers is the alias for the derived table.