SQL Queries Assignment (1)
SQL Queries Assignment (1)
Questions:
Write a query to insert a new sailor into the Sailors table.
Write an SQL query to list all sailors with a rating greater than 5.
Write a query to find the names of sailors who reserved a boat on '2024-11-01'.
Use the HAVING clause to list boats with more than 2 reservations.
Write a query to update the rating of sailor 101 by 1.
Write a query to delete sailors who are older than 50 years.
Use the ALTER statement to add a column sailor_email to the Sailors table.
Write a query to find the average rating of sailors who have reserved a boat.
Write a query to select all sailors who have reserved a boat of color 'Red'.
Create a foreign key constraint on the Reserves table referring to the Boats
table.
Questions:
Write a query to insert a new student into the Students table.
Write a query to list all courses with a duration greater than 6 weeks.
Write a query to update the course duration for 'Math' to 12 weeks.
Write a query to find all students enrolled in a course named 'Physics'.
Use the HAVING clause to find courses with more than 5 students enrolled.
Write a query to delete students who have never enrolled in a course.
Use the ALTER statement to add a new column student_address to the Students
table.
Write a query to select all students enrolled in courses of duration less than 6
weeks.
Write a query to find the number of students enrolled in each course.
Create a foreign key constraint between Enrollments and Courses.
Set 4: Customers, Orders, and Products
Schema:
Customers: (customer_id, customer_name, customer_email)
Orders: (order_id, customer_id, order_date)
Products: (product_id, product_name, product_price)
Questions:
Write a query to insert a new vehicle into the Vehicles table.
Write a query to list all vehicles older than 10 years.
Write a query to find the owner of a specific vehicle with vehicle_id 101.
Write a query to find the insurance status for a vehicle.
Use the HAVING clause to list vehicles that have had insurance for more than 2
years.
Write a query to delete insurance records that expired before '2024-01-01'.
Use the ALTER statement to add a new column vehicle_color to the Vehicles table.
Write a query to select all owners who own vehicles older than 5 years.
Write a query to find the total number of insurance policies associated with
each vehicle.
Create a foreign key constraint on the Insurance table referring to the Vehicles
table.
Questions:
Write a query to insert a new professor into the Professors table.
Write a query to list all students enrolled in a course taught by 'Prof. John'.
Write a query to update the course name for course_id 101.
Write a query to find all courses taught by a specific professor.
Use the HAVING clause to find professors who teach more than 3 courses.
Write a query to delete professors who have not taught any courses.
Use the ALTER statement to add a column professor_phone to the Professors table.
Write a query to select students enrolled in a course with more than 100
students.
Write a query to find the total number of courses taught by each professor.
Create a foreign key constraint on the Courses table referring to the Professors
table.
Questions:
Write a query to insert a new order into the Orders table.
Write a query to find all orders placed by a specific customer.
Write a query to update the status of an order to 'Shipped'.
Write a query to find the total quantity of products ordered in a specific
order.
Use the HAVING clause to find orders with more than 5 items.
Write a query to delete orders that were placed before '2023-01-01'.
Use the ALTER statement to add a new column delivery_address to the Orders
table.
Write a query to select all customers who have placed an order in the past
month.
Write a query to find the number of items in each order.
Create a foreign key constraint on the Order_Items table referring to the Orders
table.
Questions:
Write a query to insert a new movie into the Movies table.
Write a query to list all movies released after 2010.
Write a query to update the genre of the movie with movie_id 101.
Write a query to find all actors who acted in movies released after '2000'.
Use the HAVING clause to find genres with more than 5 movies.
Write a query to delete movies with a release year older than 1990.
Use the ALTER statement to add a new column director_id to the Movies table.
Write a query to select all movies directed by a specific director.
Write a query to find the average release year for movies in each genre.
Create a foreign key constraint on the Movies table referring to the Directors
table.
Questions:
Write a query to insert a new airline into the Airlines table.
Write a query to list all flights operated by 'Airline A'.
Write a query to find the average duration of all flights.
Write a query to update the flight time for a specific flight.
Use the HAVING clause to find airlines with more than 5 flights.
Write a query to delete flights that are scheduled before '2024-01-01'.
Use the ALTER statement to add a new column passenger_email to the Passengers
table.
Write a query to select all passengers who are on flights arriving after '2024-
06-01'.
Write a query to find the longest flight based on departure and arrival time.
Create a foreign key constraint on the Flights table referring to the Airlines
table.