Database: pets_1

Question: How many pets have a greater weight than 10?
SQL: SELECT count(*) FROM pets WHERE weight  >  10

Question: How much does the youngest dog weigh?
SQL: SELECT weight FROM pets ORDER BY pet_age LIMIT 1

Question: List the maximum weight and type for each type of pet.
SQL: SELECT max(weight) ,  petType FROM pets GROUP BY petType

Question: How many pets are owned by students that have an age greater than 20?
SQL: SELECT count(*) FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid WHERE T1.age  >  20

Question: How many dog pets are raised by female students?
SQL: SELECT count(*) FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T2.petid  =  T3.petid WHERE T1.sex  =  'F' AND T3.pettype  =  'dog'

Question: How many different types of pet are there?
SQL: SELECT count(DISTINCT pettype) FROM pets

Question: What are the first names of every student who has a cat or dog as a pet?
SQL: SELECT DISTINCT T1.Fname FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'cat' OR T3.pettype  =  'dog'

Question: What are the students' first names who have both cats and dogs as pets?
SQL: SELECT T1.Fname FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'cat' INTERSECT SELECT T1.Fname FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'dog'

Question: What major is every student who does not own a cat as a pet, and also how old are they?
SQL: SELECT major ,  age FROM student WHERE stuid NOT IN (SELECT T1.stuid FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'cat')

Question: What are the ids of the students who do not own cats as pets?
SQL: SELECT stuid FROM student EXCEPT SELECT T1.stuid FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'cat'

Question: What is the first name of every student who has a dog but does not have a cat?
SQL: SELECT T1.fname ,  T1.age FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'dog' AND T1.stuid NOT IN (SELECT T1.stuid FROM student AS T1 JOIN has_pet AS T2 ON T1.stuid  =  T2.stuid JOIN pets AS T3 ON T3.petid  =  T2.petid WHERE T3.pettype  =  'cat')

Question: What type of pet is the youngest animal, and how much does it weigh?
SQL: SELECT pettype ,  weight FROM pets ORDER BY pet_age LIMIT 1

Question: What is the id and weight of every pet who is older than 1?
SQL: SELECT petid ,  weight FROM pets WHERE pet_age  >  1

Question: What is the average and maximum age for each pet type?
SQL: SELECT avg(pet_age) ,  max(pet_age) ,  pettype FROM pets GROUP BY pettype

Question: What is the average weight for each type of pet?
SQL: SELECT avg(weight) ,  pettype FROM pets GROUP BY pettype