Professional Documents
Culture Documents
HW2 Updated-1
HW2 Updated-1
Individual assignment
Section:
Name:
Guidelines:
Please note that this assignment contains 15 questions.
You need to submit two files to this homework. One is your FINAL sql code (.sql), and
one is this word document with your answers. Please name your files
HW2_lastname_firstname (i.e., HW2_Chen_Peiyu.sql and HW2_Chen_Peiyu.doc or
docx), and submit your files to canvas (following appropriate hw submission link) by the
specified deadline.
By submitting your homework, you acknowledge that it is submitted as individual work
according the Academic Integrity Policy and the W.P. Carey Honor Code to the best of
your ability. Please put the following sentence after your name: “This homework is
submitted as individual work according the Academic Integrity Policy and the W.P.
Carey Honor Code to the best of my ability”. If it is not true, state why it is not true.
Objective
This exercise will enable you to demonstrate mastery of fundamental SQL queries on a
DBMS.
Instructions:
Use MySQL workbench and connect to the course server. The database to use is
apps_and_crunchbase. The relevant schema (the apps schema) is provided as a separate
file along with this homework. Please make sure you execute the following statement
before writing your queries.
use apps_and_crunchbase;
Develop the solution to each question, and paste the SQL query in the space provided
below each question. Please make sure you provide queries that would retrieve just
the information asked in the question, no more and no less. For example, if you are
asked how many apps, then your query should just return a number. For results
reporting, you may be asked to report only a subset of the entire returned results for some
questions (for example, report the first 5 rows); for some other questions, you may be
asked to report only the number of rows returned by your query. Please report as asked.
Relevant data of these apps were also collected and stored in the apps table.
Query:
select *
from apps
where name = 'Twitter';
Result:
2. Retrieve the name and price for the apps whose name contains the string "sun" (hint:
can begin with "sun", end with "sun", or have "sun" in the middle (e.g. Samsung)
Query:
from apps
Row Count:
280
Query:
select count(id)
from apps
where seller_url is not null;
Result:
72096
Query:
select distinct(category_primary)
from apps;
Row count: 22
5 Retrieve the min, average, max prices for the primary category ‘Finance’
Query:
from apps
Result:
6. Show the distribution of the price of apps. In other words, list all of the prices with the
count of the apps at a given price. Please order your results by price in ascending
order. (Hint, you should have two columns in your result: price and count. If you are
interested in knowing the price structure of apps, you might want to read the first few
paragraphs of this article).
Query:
group by price
order by price;
Result: please copy the first 5 results from your result table which should have more than 5 rows
Row count: 82
7. What is the mean price among the paid apps for each primary category? List in
descending order of the mean price. Hint: Paid apps mean price >0. Please consider just
the primary category for each app. Please use the apps table.
Query:
select category_primary, avg(price)
from apps
where price > 0
group by category_primary
order by avg(price) desc;
Medical 11.309511
Business 10.393448
Navigation 7.250569
Finance 5.187545
Reference 4.830146
Query:
from apps
group by developer_name
limit 10;
Result:
9. Retrieve the developer id and name for the developers who developed apps in at least 10
primary categories;
Query:
Row count:
10. Are there apps with the same name? Please write a query to show names that are
shared by multiple apps and how many apps share each of these common names.
Query:
Row count:
II Multi-Table Queries
11. Retrieve the name of the app that has the highest number of ratings (i.e., rating_count)
and the number of ratings it received.
Query:
Result:
12. Retrieve the name and primary category for the apps that are game-center enabled and
whose primary category is not "Games" (use apps table).
Query:
Row count:
13. In which primary category, the apps have the highest mean
average_rating?
Query:
Result:
14. List the total number of ratings (rating_count) received for each primary category?
Please list them in descending order of the total number of ratings.
Query:
15. List the primary category, number of ratings and average ratings for the app “Google
Earth”.
Query:
Result: