Exercises InterfacePythonWithMySQL
Exercises InterfacePythonWithMySQL
We consider a dataset that includes data from a research by Stanley Coren, a professor of canine
psychology at the University of British Columbia (Canada), as well as breed size data for dogs from
the American Kennel Club (AKC).
The dataset consists of two tables, stored as CSV (comma-separated values) files:
dog_intelligence.csv and breed_info.csv.
The first line of each file contains the headers of the columns (separated by commas). The other
lines are the rows of the table, which contain the values of the corresponding fields.
dog_intelligence.csv
The first four lines of the file and the corresponding table:
breed,classification,obey,reps_lower,reps_upper
Affenpinscher,Above Average Working Dogs,0.7,16,25
Afghan Hound,Lowest Degree of Working/Obedience Intelligence,0.2,81,100
Airedale Terrier,Above Average Working Dogs,0.7,16,25
breed_info.csv
The first four lines of the file and the corresponding table:
breed,height_low_inches,height_high_inches,weight_low_lbs,weight_high_lbs
Affenpinscher,9,12,8,12
Afghan Hound,25,27,50,60
Airedale Terrier,22,24,45,45
Exercise 2
We want to understand whether there is a correlation between dog size and intelligence. To do
this, perform the following queries in the database “dogs” (use MySQL Connector Python):
1. Report all the breeds that are classified as “Brightest Dogs”, their average height and
weight.
2. Report all the breeds that are classified as “Lowest Degree of Working/Obedience
Intelligence”, their average height and weight.
3. Report all the breeds whose obey field is at least 0.7, their average height and weight.
4. Report all the breeds whose obey field is at most 0.3, their average height and weight.
5. For each classification, report: the maximum and the minimum height; the maximum and
the minimum weight.
Assume the following:
• a breed is small if weight_avg_inches < 23;
• a breed is medium if 22 < weight_avg_inches < 56;
• a breed is large if weight_avg_inches > 55.
6. Report the number of small breeds whose obey field is at least 0.7.
7. Report the number of medium breeds whose obey field is at least 0.7.
8. Report the number of large breeds whose obey field is at least 0.7.
9. Report the number of small breeds whose obey field is at most 0.3.
10. Report the number of medium breeds whose obey field is at most 0.3.
11. Report the number of large breeds whose obey field is at most 0.3.
12. Report all the small breeds and their obey field and order them by descending obey.
13. Report all the medium breeds and their obey field and order them by descending obey.
14. Report all the large breeds and their obey field and order them by descending obey.