CREATE DATABASE menagerie;
USE menagerie;
1. GROUP BY & HAVING
Question 1: Write a query to find the total number of pets owned by each owner.
Question 2: Find all types of species that have more than 2 pets in the database.
Question 3: List the owners who own more than 2 pets, along with the total count of pets they own.
Question 4: Calculate the average age of pets for each species, but only include species where the average age is greater than 30 years
2. Equijoins
Question 5: Write a query to display each pet's name, their species, and the date of any event they participated in.
Question 6: Find the names of all pets, their owners, and the specific type (
type) of events where the remark contains the word "birthday".Question 7: List all pets (name and species) who have had a "vet" event, along with the date and the specific remark recorded by the vet.
3. Natural Joins
Question 8: Using a
NATURAL JOIN, retrieve a list of all pets who have recorded events, showing the pet's name, birth date, event date, and remarks.Question 9: Write a query using a natural join to find all female pets (
sex = 'f') that have experienced an event, displaying their name, species, and the event type.
4. Subqueries
Question 10: Write a query to find all pets that are younger than the average age of all pets in the database.
Question 11: Find the names and species of all pets that have never participated in any event
Question 12: List the names of all pets that have had an event on the exact same date that 'Fluffy' had an event.
No comments:
Post a Comment