0
0
MySQLquery~10 mins

View limitations in MySQL - Interactive Code Practice

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'.

MySQL
CREATE VIEW active_users AS SELECT * FROM users WHERE status = '[1]';
Drag options to blanks, or click blank then click option'
Ainactive
Bdeleted
Cactive
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Using status values other than 'active' will show wrong users.
Forgetting quotes around the status value causes syntax errors.
2fill in blank
medium

Complete the code to select from a view named 'sales_summary' only the rows where total_sales is greater than 1000.

MySQL
SELECT * FROM sales_summary WHERE total_sales [1] 1000;
Drag options to blanks, or click blank then click option'
A>
B<=
C=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' will select smaller or equal values, not greater.
Using '=' will select only rows with exactly 1000 sales.
3fill in blank
hard

Fix the error in the view creation by completing the code to avoid using a non-deterministic function in the view.

MySQL
CREATE VIEW current_time_view AS SELECT [1] AS now_time;
Drag options to blanks, or click blank then click option'
AUUID
BNOW
CRAND
DCURRENT_DATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOW() or RAND() causes errors because they are non-deterministic.
Using UUID() is also non-deterministic and not allowed in views.
4fill in blank
hard

Fill both blanks to create a view that selects user_id and the count of orders, grouping by user_id.

MySQL
CREATE VIEW user_order_counts AS SELECT user_id, COUNT([1]) AS order_count FROM orders GROUP BY [2];
Drag options to blanks, or click blank then click option'
Aorder_id
Buser_id
Cstatus
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Counting user_id instead of order_id counts users, not orders.
Grouping by order_id groups by each order, not user.
5fill in blank
hard

Fill all three blanks to create a view that shows product names, total quantity sold, and only includes products with total quantity greater than 50.

MySQL
CREATE VIEW popular_products AS SELECT [1], SUM([2]) AS total_sold FROM sales GROUP BY [3] HAVING total_sold > 50;
Drag options to blanks, or click blank then click option'
Aproduct_name
Bquantity
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by quantity or price instead of product_name causes wrong grouping.
Summing price instead of quantity does not count units sold.