Complete the code to select all columns from a derived table named 'sub'.
SELECT [1] FROM (SELECT id, name FROM employees) AS sub;Using * selects all columns from the derived table sub.
Complete the code to alias the derived table as 'dept_avg'.
SELECT department, avg_salary FROM (SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department) AS [1];The alias dept_avg names the derived table for use in the outer query.
Fix the error in the code by completing the alias for the derived table.
SELECT name, total_sales FROM (SELECT name, SUM(sales) AS total_sales FROM sales_data GROUP BY name) [1];AS incorrectly after the derived table.The derived table must have an alias without the keyword AS in this position; just the alias name sales_summary is correct.
Fill both blanks to select the average salary and alias the derived table correctly.
SELECT department, [1] FROM (SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department) [2];
The outer query selects the alias avg_salary from the derived table, which is aliased as dept_avg.
Fill all three blanks to create a derived table that calculates total sales per region and select from it.
SELECT [1], [2] FROM (SELECT region, SUM(sales) AS [3] FROM sales GROUP BY region) sales_totals;
The outer query selects region and total_sales from the derived table. The derived table aliases the sum as total_sales.