MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph,...

15
© 2015 Consort Institute, LLC. All right reserved. This material may not be reproduced, displayed, modified or distributed in any forms by any means without the express prior written permission of Consort Institute, LLC MySQL World Database by Robert Joseph, Ph.D.

Transcript of MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph,...

Page 1: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

© 2015 Consort Institute, LLC. All right reserved. This material may not be reproduced, displayed, modified or distributed in any forms by any means without the express prior written permission of Consort Institute, LLC

MySQLWorld Database

by Robert Joseph, Ph.D.

Page 2: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

World Database

2

You are a new hire company Worldwide Furniture. As the name says this company does furniture sales all over the world.

Understanding different aspects of country, city and language information is essential for the sales team to be able to be

successful. If the sales team is not successful the company can not survive. Your predecessor created a world database but left no

documentation and did not complete the reporting. Your boss needs you to get the database back up and running then answer

some questions that still need to be answered. First think about what questions might a sales team have based on the database

you have access to. Then answer those questions you have developed as well as the set of questions that follow. Present your set

of findings using an excel spreadsheet.

1. Download world.sql file from world database at location https://dev.mysql.com/doc/index-other.html

2. In a text editor comment out the values below. These will create a different database that you don’t have the privledges:

/*

DROP SCHEMA IF EXISTS world;

CREATE SCHEMA world;

USE world;

SET AUTOCOMMIT=0;

*/

1. Import the modified file into your studentXXXX database

2. Develop a set of questions that you want to answer based on the data that you are given and combine those questions

with the ones that are listed.

3. Now map out the steps you will take to answer the questions that follow.

Page 3: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

One Method To AnswersThere is more than one way to get to the answer. What follows is just one method for getting the answers.

3

Page 4: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

1. You should now see 3 additional tables city, country and countrylanguage2. From this data create an ER Diagram

4

Page 5: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Questions 1 - 61. How many countries are in the database

2. What are the top 10 largest countries

3. What are the top 10 GDP countries

4. What are the intersection between the two

5. For the above countries what is the % English

6. What is the top most populated countries

5

Page 6: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Questions 7 - 107. What are the top 10 countries that have the smallest people to land ratio

8. What are the top 10 countries that have the largest people to land ratios

9. What are the countries that speak over 50% English

10. How many different languages are there

6

Page 7: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Questions 11 - 1211. What is the number of languages are spoken in different country.

12. What are the top 10 languages spoken in different countries along with their count

7

Page 8: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 1 - 31. How many countries are in the database

select count(distinct(name)) from country

2. What are the top 10 largest countriesselect name, SurfaceArea from country ORDER BY SurfaceArea desc Limit 10

3. What are the top 10 GDP countriesselect name, GNP from country ORDER BY GNP desc Limit 10

8

Page 9: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 44. What are the intersection between the two

select GNP INTO @g from country ORDER BY GNP desc LIMIT 9,1;

SELECT SurfaceArea INTO @s from country Order By SurfaceArea desc Limit 9,1;

SELECT Name, GNP, SurfaceArea FROM country WHERE GNP > @g and SurfaceArea > @sORDER BY GNP desc;

9

Page 10: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 55. For the above countries what is the % English

SELECT GNP INTO @g from country ORDER BY GNP desc LIMIT 9,1;

SELECT SurfaceArea INTO @s from country ORDER BY SurfaceArea desc LIMIT 9,1;

SELECT Name, GNP, SurfaceArea, Percentage FROM countryLEFT JOIN countrylanguage ON CountryCode = Code and language = 'English'WHERE GNP > @g and SurfaceArea > @sORDER BY GNP desc

10

Page 11: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 6 - 76. What is the top most populated countries

SELECT name, Convert(Population,UNSIGNED INTEGER) as p FROM country ORDER BY p desc Limit 1,1

7. What are the top 10 countries that have the smallest people to land ratio

SELECT name, Population, SurfaceArea, (Population/SurfaceArea) as p FROM country ORDER BY p Desc Limit 0,9

11

Page 12: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 88. What are the top 10 countries that have the largest people to land ratios

SELECT name, Population, SurfaceArea, (Population/SurfaceArea) as p FROM country ORDER BY p Asc Limit 0,9

12

Page 13: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 9 - 109. What are the countries that speak over 50% English

SELECT Name, Language, Percentage FROM country, countrylanguage WHERE CountryCode = Code and

Language = "English" andPercentage > 50

ORDER BY Percentage desc

10. How many different languages are thereSELECT count(distinct(Language)) FROM `countrylanguage`

13

Page 14: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

ece.emory.edu | 404.727.6000 | [email protected]

Answers 11 - 12 11. What is the number of languages are spoken in different country.

SELECT language, count(language) as ct FROM countrylanguage GROUP BY language ORDER BY ct desc

12. What are the top 10 languages spoken in different countries along with their count

SELECT language, count(language) as ct FROM countrylanguage GROUP BY language ORDER BY ct desc LIMIT 1, 10

14

Page 15: MySQL World Databasemysql.emoryce.com/data/WorldDatabase.pdfMySQL World Database by Robert Joseph, Ph.D. ece.emory.edu | 404.727.6000 | ece@emory.edu World Database 2 You are a new

© 2015 Consort Institute, LLC. All right reserved. This material may not be reproduced, displayed, modified or distributed in any forms by any means without the express prior written permission of Consort Institute, LLC

Live Long and Prosper