Assignment 1
Basic Assignments
Select All Rows
Write a query to fetch all rows from the
user2table.
Filter by City
Retrieve all users from the
user2table who live inNew York.
Filter by Hobby
Retrieve all users whose hobby is
Reading.
Count Rows
Write a query to count the total number of users in the
user2table.
Sort by Name
Write a query to fetch all rows, sorting them alphabetically by the
namecolumn.
Intermediate Assignments
Unique Cities
Write a query to find all unique cities in the
user2table.
Group by Hobby
Write a query to group users by their hobbies and count how many users have each hobby.
Add a New Column
Write a query to add a new column
ageto theuser2table.
Update Hobby
Write a query to update the
hobbyof a user namedAlicetoPainting.
Delete a Row
Write a query to delete the row where the user has the name
John.
Advanced Assignments
Insert Data
Insert three new rows into the
user2table with values:('Alice', 'Boston', 'Dancing')('Bob', 'Seattle', 'Cooking')('Charlie', 'San Francisco', 'Traveling')
Join with Another Table
Create another table
user_detailswith columns:name,email,phone. Write a query to joinuser2anduser_detailson thenamecolumn.
Find Most Common Hobby
Write a query to find the most common hobby in the
user2table.
Conditional Aggregation
Write a query to count how many users live in
New Yorkand how many live inSan Francisco.
Subquery
Write a query to fetch users whose city is the same as the user named
Alice.
Bonus Assignments
Create a View
Create a view
user_hobby_countthat displays each hobby and the number of users with that hobby.
Add Constraints
Alter the
user2table to add a constraint where thenamecolumn cannot have duplicate values.
Find Hobby for Each City
Write a query to list each city and the hobbies of users from that city.
Case Statement
Write a query that displays a new column
categorywhere:If the hobby is
Reading, the category isIntellectual.If the hobby is
Dancing, the category isArtistic.Otherwise, the category is
Other.
Backup and Restore
Write a query to copy the contents of the
user2table into another tableuser2_backup.
Last updated