0
0
SQLquery~10 mins

UPDATE with subquery preview in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the salary of employees to 50000 where their department is 'Sales'.

SQL
UPDATE employees SET salary = [1] WHERE department = 'Sales';
Drag options to blanks, or click blank then click option'
ANULL
B50000
Csalary + 50000
D'50000'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 50000 in quotes, which makes it a string.
Using salary + 50000 which adds instead of setting.
2fill in blank
medium

Complete the code to update the salary of employees to the average salary of their department.

SQL
UPDATE employees SET salary = (SELECT AVG(salary) FROM employees WHERE department = [1]);
Drag options to blanks, or click blank then click option'
Adepartment
Bsalary
C'department'
D'Sales'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around department, making it a string instead of a column.
Using salary instead of department.
3fill in blank
hard

Fix the error in the code to update employees' salary to the maximum salary in their department.

SQL
UPDATE employees SET salary = (SELECT MAX(salary) FROM employees WHERE department = [1]);
Drag options to blanks, or click blank then click option'
Adepartment
B'Sales'
C'department'
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around department.
Using a fixed string like 'Sales' instead of the column.
4fill in blank
hard

Fill both blanks to update employees' bonus to 10% of their salary where their department is 'Sales'.

SQL
UPDATE employees SET bonus = salary * [1] WHERE department = [2];
Drag options to blanks, or click blank then click option'
A0.1
B'Sales'
Cdepartment
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 instead of 0.1 for percentage.
Not quoting the department string.
5fill in blank
hard

Fill all three blanks to update employees' salary to the average salary of their department only if their current salary is below that average.

SQL
UPDATE employees SET salary = (SELECT AVG(salary) FROM employees WHERE department = [1]) WHERE salary < (SELECT AVG(salary) FROM employees WHERE department = [2]) AND department = [3];
Drag options to blanks, or click blank then click option'
Adepartment
B'HR'
C'Sales'
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting the department column in subqueries.
Not quoting the department string in the WHERE clause.