Database: dog_kennels
# breeds ( breed_code , breed_name )
# charges ( charge_id , charge_type , charge_amount )
# sizes ( size_code , size_description )
# treatment_types ( treatment_type_code , treatment_type_description )
# owners ( owner_id , first_name , last_name , street , city , state , zip_code , email_address , home_phone , cell_number )
# dogs ( dog_id , owner_id , abandoned_yn , breed_code , size_code , name , age , date_of_birth , gender , weight , date_arrived , date_adopted , date_departed )
# professionals ( professional_id , role_code , first_name , street , city , state , zip_code , last_name , email_address , home_phone , cell_number )
# treatments ( treatment_id , dog_id , professional_id , treatment_type_code , date_of_treatment , cost_of_treatment )
# dogs.owner_id = owners.owner_id
# dogs.owner_id = owners.owner_id
# dogs.size_code = sizes.size_code
# dogs.breed_code = breeds.breed_code
# treatments.dog_id = dogs.dog_id
# treatments.professional_id = professionals.professional_id
# treatments.treatment_type_code = treatment_types.treatment_type_code

Question: Which states have both owners and professionals living there?
SQL: select state from owners intersect select state from professionals

Question: Find the states where both owners and professionals live.
SQL: select state from owners intersect select state from professionals

Question: What is the average age of the dogs who have gone through any treatments?
SQL: select avg ( age ) from dogs where dog_id in ( select dog_id from treatments )

Question: Find the average age of the dogs who went through treatments.
SQL: select avg ( age ) from dogs where dog_id in ( select dog_id from treatments )

Question: Which professionals live in the state of Indiana or have done treatment on more than 2 treatments? List his or her id, last name and cell phone.
SQL: select professional_id , last_name , cell_number from professionals where state = 'Indiana' union select professionals.professional_id , professionals.last_name , professionals.cell_number from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) > 2

Question: Find the id, last name and cell phone of the professionals who live in the state of Indiana or have performed more than two treatments.
SQL: select professional_id , last_name , cell_number from professionals where state = 'Indiana' union select professionals.professional_id , professionals.last_name , professionals.cell_number from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) > 2

Question: Which dogs have not cost their owner more than 1000 for treatment ? List the dog names .
SQL: select name from dogs where dog_id not in ( select dog_id from treatments group by dog_id having sum ( cost_of_treatment ) > 1000 )

Question: What are the names of the dogs for which the owner has not spend more than 1000 for treatment ?
SQL: select name from dogs where dog_id not in ( select dog_id from treatments group by dog_id having sum ( cost_of_treatment ) > 1000 )

Question: Which first names are used for professionals or owners but are not used as dog names?
SQL: select first_name from professionals union select first_name from owners except select name from dogs

Question: Find the first names that are used for professionals or owners but are not used as dog names.
SQL: select first_name from professionals union select first_name from owners except select name from dogs

Question: Which professional did not operate any treatment on dogs? List the professional's id, role and email.
SQL: select professional_id , role_code , email_address from professionals except select professionals.professional_id , professionals.role_code , professionals.email_address from professionals join treatments on professionals.professional_id = treatments.professional_id

Question: Give me the id, role and email of the professionals who did not perform any treatment on dogs.
SQL: select professional_id , role_code , email_address from professionals except select professionals.professional_id , professionals.role_code , professionals.email_address from professionals join treatments on professionals.professional_id = treatments.professional_id

Question: Which owner owns the most dogs? List the owner id, first name and last name.
SQL: select dogs.owner_id , owners.first_name , owners.last_name from dogs join owners on dogs.owner_id = owners.owner_id group by dogs.owner_id order by count ( * ) desc limit 1

Question: Return the owner id, first name and last name of the owner who has the most dogs.
SQL: select dogs.owner_id , owners.first_name , owners.last_name from dogs join owners on dogs.owner_id = owners.owner_id group by dogs.owner_id order by count ( * ) desc limit 1

Question: Which professionals have done at least two treatments? List the professional's id, role, and first name.
SQL: select professionals.professional_id , professionals.role_code , professionals.first_name from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) >= 2

Question: What are the id, role, and first name of the professionals who have performed two or more treatments?
SQL: select professionals.professional_id , professionals.role_code , professionals.first_name from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) >= 2

Question: What is the name of the breed with the most dogs?
SQL: select breeds.breed_name from breeds join dogs on breeds.breed_code = dogs.breed_code group by breeds.breed_name order by count ( * ) desc limit 1

Question: Which breed do the most dogs have? Give me the breed name.
SQL: select breeds.breed_name from breeds join dogs on breeds.breed_code = dogs.breed_code group by breeds.breed_name order by count ( * ) desc limit 1

Question: Which owner has paid for the most treatments on his or her dogs? List the owner id and last name.
SQL: select owners.owner_id , owners.last_name from owners join dogs on owners.owner_id = dogs.owner_id join treatments on dogs.dog_id = treatments.dog_id group by owners.owner_id order by count ( * ) desc limit 1

Question: Tell me the owner id and last name of the owner who spent the most on treatments of his or her dogs.
SQL: select owners.owner_id , owners.last_name from owners join dogs on owners.owner_id = dogs.owner_id join treatments on dogs.dog_id = treatments.dog_id group by owners.owner_id order by count ( * ) desc limit 1

Question: What is the description of the treatment type that costs the least money in total?
SQL: select treatment_types.treatment_type_description from treatment_types join treatments on treatment_types.treatment_type_code = treatments.treatment_type_code group by treatment_types.treatment_type_code order by sum ( cost_of_treatment ) asc limit 1

Question: Give me the description of the treatment type whose total cost is the lowest.
SQL: select treatment_types.treatment_type_description from treatment_types join treatments on treatment_types.treatment_type_code = treatments.treatment_type_code group by treatment_types.treatment_type_code order by sum ( cost_of_treatment ) asc limit 1

Question: Which owner has paid the largest amount of money in total for their dogs? Show the owner id and zip code.
SQL: select owners.owner_id , owners.zip_code from owners join dogs on owners.owner_id = dogs.owner_id join treatments on dogs.dog_id = treatments.dog_id group by owners.owner_id order by sum ( treatments.cost_of_treatment ) desc limit 1

Question: Find the owner id and zip code of the owner who spent the most money in total for his or her dogs.
SQL: select owners.owner_id , owners.zip_code from owners join dogs on owners.owner_id = dogs.owner_id join treatments on dogs.dog_id = treatments.dog_id group by owners.owner_id order by sum ( treatments.cost_of_treatment ) desc limit 1

Question: Which professionals have done at least two types of treatments? List the professional id and cell phone.
SQL: select professionals.professional_id , professionals.cell_number from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) >= 2

Question: Find the id and cell phone of the professionals who operate two or more types of treatments.
SQL: select professionals.professional_id , professionals.cell_number from professionals join treatments on professionals.professional_id = treatments.professional_id group by professionals.professional_id having count ( * ) >= 2

Question: What are the first name and last name of the professionals who have done treatment with cost below average?
SQL: select distinct professionals.first_name , professionals.last_name from professionals join treatments where cost_of_treatment < ( select avg ( cost_of_treatment ) from treatments )

Question: Which professionals have operated a treatment that costs less than the average? Give me theor first names and last names.
SQL: select distinct professionals.first_name , professionals.last_name from professionals join treatments where cost_of_treatment < ( select avg ( cost_of_treatment ) from treatments )

Question: List the date of each treatment, together with the first name of the professional who operated it.
SQL: select treatments.date_of_treatment , professionals.first_name from treatments join professionals on treatments.professional_id = professionals.professional_id

Question: What are the date and the operating professional's first name of each treatment?
SQL: select treatments.date_of_treatment , professionals.first_name from treatments join professionals on treatments.professional_id = professionals.professional_id

Question: List the cost of each treatment and the corresponding treatment type description.
SQL: select treatments.cost_of_treatment , treatment_types.treatment_type_description from treatments join treatment_types on treatments.treatment_type_code = treatment_types.treatment_type_code

Question: What are the cost and treatment type description of each treatment?
SQL: select treatments.cost_of_treatment , treatment_types.treatment_type_description from treatments join treatment_types on treatments.treatment_type_code = treatment_types.treatment_type_code

Question: List each owner's first name, last name, and the size of his for her dog.
SQL: select owners.first_name , owners.last_name , dogs.size_code from owners join dogs on owners.owner_id = dogs.owner_id

Question: What are each owner's first name, last name, and the size of their dog?
SQL: select owners.first_name , owners.last_name , dogs.size_code from owners join dogs on owners.owner_id = dogs.owner_id

Question: List pairs of the owner's first name and the dogs's name.
SQL: select owners.first_name , dogs.name from owners join dogs on owners.owner_id = dogs.owner_id

Question: What are each owner's first name and their dogs's name?
SQL: select owners.first_name , dogs.name from owners join dogs on owners.owner_id = dogs.owner_id

Question: List the names of the dogs of the rarest breed and the treatment dates of them.
SQL: select dogs.name , treatments.date_of_treatment from dogs join treatments on dogs.dog_id = treatments.dog_id where dogs.breed_code = ( select breed_code from dogs group by breed_code order by count ( * ) asc limit 1 )

Question: Which dogs are of the rarest breed? Show their names and treatment dates.
SQL: select dogs.name , treatments.date_of_treatment from dogs join treatments on dogs.dog_id = treatments.dog_id where dogs.breed_code = ( select breed_code from dogs group by breed_code order by count ( * ) asc limit 1 )

Question: Which dogs are owned by someone who lives in Virginia? List the owner's first name and the dog's name.
SQL: select owners.first_name , dogs.name from owners join dogs on owners.owner_id = dogs.owner_id where owners.state = 'Virginia'

Question: Find the first names of owners living in Virginia and the names of dogs they own.
SQL: select owners.first_name , dogs.name from owners join dogs on owners.owner_id = dogs.owner_id where owners.state = 'Virginia'

Question: What are the arriving date and the departing date of the dogs who have gone through a treatment?
SQL: select distinct dogs.date_arrived , dogs.date_departed from dogs join treatments on dogs.dog_id = treatments.dog_id

Question: Find the arriving date and the departing date of the dogs that received a treatment.
SQL: select distinct dogs.date_arrived , dogs.date_departed from dogs join treatments on dogs.dog_id = treatments.dog_id

Question: List the last name of the owner owning the youngest dog.
SQL: select owners.last_name from owners join dogs on owners.owner_id = dogs.owner_id where dogs.age = ( select max ( age ) from dogs )

Question: Who owns the youngest dog? Give me his or her last name.
SQL: select owners.last_name from owners join dogs on owners.owner_id = dogs.owner_id where dogs.age = ( select max ( age ) from dogs )

Question: List the emails of the professionals who live in the state of Hawaii or the state of Wisconsin.
SQL: select email_address from professionals where state = 'Hawaii' or state = 'Wisconsin'

Question: What are the emails of the professionals living in either the state of Hawaii or the state of Wisconsin?
SQL: select email_address from professionals where state = 'Hawaii' or state = 'Wisconsin'

Question: What are the arriving date and the departing date of all the dogs?
SQL: select date_arrived , date_departed from dogs

Question: List the arrival date and the departure date for all the dogs.
SQL: select date_arrived , date_departed from dogs

Question: How many dogs went through any treatments?
SQL: select count ( distinct dog_id ) from treatments

Question: Count the number of dogs that went through a treatment.
SQL: select count ( distinct dog_id ) from treatments

Question: How many professionals have performed any treatment to dogs?
SQL: select count ( distinct professional_id ) from treatments

Question: Find the number of professionals who have ever treated dogs.
SQL: select count ( distinct professional_id ) from treatments

Question: Which professionals live in a city containing the substring 'West'? List his or her role, street, city and state.
SQL: select role_code , street , city , state from professionals where city like '%West%'

Question: Find the role, street, city and state of the professionals living in a city that contains the substring 'West'.
SQL: select role_code , street , city , state from professionals where city like '%West%'

Question: Which owners live in the state whose name contains the substring 'North'? List his first name, last name and email.
SQL: select first_name , last_name , email_address from owners where state like '%North%'

Question: Return the first name, last name and email of the owners living in a state whose name contains the substring 'North'.
SQL: select first_name , last_name , email_address from owners where state like '%North%'

Question: How many dogs have an age below the average?
SQL: select count ( * ) from dogs where age < ( select avg ( age ) from dogs )

Question: Count the number of dogs of an age below the average.
SQL: select count ( * ) from dogs where age < ( select avg ( age ) from dogs )

Question: How much does the most recent treatment cost?
SQL: select cost_of_treatment from treatments order by date_of_treatment desc limit 1

Question: Show me the cost of the most recently performed treatment.
SQL: select cost_of_treatment from treatments order by date_of_treatment desc limit 1

Question: How many dogs have not gone through any treatment?
SQL: select count ( * ) from dogs where dog_id not in ( select dog_id from treatments )

Question: Tell me the number of dogs that have not received any treatment .
SQL: select count ( * ) from dogs where dog_id not in ( select dog_id from treatments )

Question: How many owners temporarily do not have any dogs?
SQL: select count ( * ) from owners where owner_id not in ( select owner_id from dogs )

Question: Find the number of owners who do not own any dogs at this moment.
SQL: select count ( * ) from owners where owner_id not in ( select owner_id from dogs )

Question: How many professionals did not operate any treatment on dogs?
SQL: select count ( * ) from professionals where professional_id not in ( select professional_id from treatments )

Question: Find the number of professionals who have not treated any dogs.
SQL: select count ( * ) from professionals where professional_id not in ( select professional_id from treatments )

Question: List the dog name, age and weight of the dogs who have been abandoned? 1 stands for yes, and 0 stands for no.
SQL: select name , age , weight from dogs where abandoned_yn = 1

Question: What are the dog name, age and weight of the dogs that were abandoned? Note that 1 stands for yes, and 0 stands for no in the tables.
SQL: select name , age , weight from dogs where abandoned_yn = 1

Question: What is the average age of all the dogs?
SQL: select avg ( age ) from dogs

Question: Compute the average age of all the dogs.
SQL: select avg ( age ) from dogs

Question: What is the age of the oldest dog?
SQL: select max ( age ) from dogs

Question: Tell me the age of the oldest dog.
SQL: select max ( age ) from dogs

Question: How much does each charge type costs? List both charge type and amount.
SQL: select charge_type , charge_amount from charges

Question: List each charge type and its amount.
SQL: select charge_type , charge_amount from charges

Question: How much does the most expensive charge type costs?
SQL: select max ( charge_amount ) from charges

Question: What is the charge amount of the most expensive charge type?
SQL: select max ( charge_amount ) from charges

Question: List the email, cell phone and home phone of all the professionals.
SQL: select email_address , cell_number , home_phone from professionals

Question: What are the email, cell phone and home phone of each professional?
SQL: select email_address , cell_number , home_phone from professionals

Question: What are all the possible breed type and size type combinations?
SQL: select distinct breed_code , size_code from dogs

Question: Find the distinct breed type and size type combinations for dogs.
SQL: select distinct breed_code , size_code from dogs

Question: List the first name of all the professionals along with the description of the treatment they have done.
SQL: select distinct professionals.first_name , treatment_types.treatment_type_description from professionals join treatments on professionals.professional_id = treatments.professional_id join treatment_types on treatments.treatment_type_code = treatment_types.treatment_type_code

Question: What are each professional's first name and description of the treatment they have performed?
SQL: select distinct professionals.first_name , treatment_types.treatment_type_description from professionals join treatments on professionals.professional_id = treatments.professional_id join treatment_types on treatments.treatment_type_code = treatment_types.treatment_type_code