0
0
PostgreSQLquery~10 mins

Why views matter in PostgreSQL - Test Your Understanding

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

Complete the code to create a simple view named 'active_users' that shows users with status 'active'.

PostgreSQL
CREATE VIEW active_users AS SELECT * FROM users WHERE status = '[1]';
Drag options to blanks, or click blank then click option'
Aactive
Binactive
Cpending
Ddeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a status other than 'active' will show wrong users.
Leaving the status blank will cause a syntax error.
2fill in blank
medium

Complete the code to select all columns from the view 'active_users'.

PostgreSQL
SELECT [1] FROM active_users;
Drag options to blanks, or click blank then click option'
Aid
Bname
C*
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting a single column when all columns are needed.
Using an invalid column name.
3fill in blank
hard

Fix the error in the view definition by completing the missing keyword.

PostgreSQL
CREATE [1] active_users AS SELECT * FROM users WHERE status = 'active';
Drag options to blanks, or click blank then click option'
AFUNCTION
BINDEX
CTABLE
DVIEW
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TABLE' instead of 'VIEW' causes syntax errors.
Using 'INDEX' or 'FUNCTION' is incorrect for views.
4fill in blank
hard

Fill both blanks to create a view that shows orders with amount greater than 100.

PostgreSQL
CREATE [1] high_value_orders AS SELECT * FROM orders WHERE amount [2] 100;
Drag options to blanks, or click blank then click option'
AVIEW
B>
C<
DTABLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TABLE' instead of 'VIEW' causes errors.
Using '<' instead of '>' filters wrong rows.
5fill in blank
hard

Fill all three blanks to create a view that shows product names and prices where price is less than 50.

PostgreSQL
CREATE [1] affordable_products AS SELECT [2], price FROM products WHERE price [3] 50;
Drag options to blanks, or click blank then click option'
AVIEW
Bname
C<
DTABLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TABLE' instead of 'VIEW' causes errors.
Selecting wrong column instead of 'name'.
Using '>' instead of '<' filters wrong products.