0
0
PostgreSQLquery~10 mins

Why PostgreSQL advanced features matter - Test Your Understanding

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

Complete the code to select all columns from the table named employees.

PostgreSQL
SELECT [1] FROM employees;
Drag options to blanks, or click blank then click option'
A*
Ball
Ceverything
Dcolumns
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'all' or 'columns' instead of the symbol *
Leaving the SELECT statement incomplete
2fill in blank
medium

Complete the code to filter rows where the salary is greater than 50000.

PostgreSQL
SELECT * FROM employees WHERE salary [1] 50000;
Drag options to blanks, or click blank then click option'
A=
B>
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which selects only salaries exactly 50000
Using '<' which selects salaries less than 50000
3fill in blank
hard

Fix the error in the query to count the number of employees.

PostgreSQL
SELECT COUNT([1]) FROM employees;
Drag options to blanks, or click blank then click option'
Aemployee_id
Bsalary
Cname
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Counting a specific column which may miss rows with NULL values
Leaving COUNT empty or with invalid syntax
4fill in blank
hard

Fill both blanks to create a dictionary of employee names and their salaries where salary is above 60000.

PostgreSQL
SELECT jsonb_object_agg([1], [2]) FROM employees WHERE salary > 60000;
Drag options to blanks, or click blank then click option'
Aname
Bsalary
Cemployee_id
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values
Using columns not relevant to the dictionary
5fill in blank
hard

Fill all three blanks to create a JSON object with employee names as keys, their salaries as values, but only include those in the 'Sales' department.

PostgreSQL
SELECT jsonb_object_agg([1], [2]) FROM employees WHERE department = '[3]';
Drag options to blanks, or click blank then click option'
Aname
Bsalary
CSales
DMarketing
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong department name
Swapping keys and values in jsonb_object_agg