Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. Consider a review website with the following schema, where underlined values indicate the primary key. Provide SELECT statements corresponding to the questions below Businesses
4. Consider a review website with the following schema, where underlined values indicate the primary key. Provide SELECT statements corresponding to the questions below Businesses (ID:int, Name:string, City:string, state:varchar (2)) * Each business has a name, unique ID, and is located in a specific city and state. Users(ID:int, Name: string, Followers:int) * Each users has a name, unique ID, and a number of followers Reviews (bID:int, uID:int, Stars:int, Date:date, useful:int, funny:int, cool:int) * Each user gives a review to a business by assigning a number of stars to it. The review is made on a specific date and a number of others may have found it useful, funny or cool BusinessTypes (bID:int, Type:string) * Each business is of a certain type (e.g., restaurant, construction, dinner SUGGESTION: It could be useful, but not necessary, to create the four tables in MySQL and populate them with data to test your queries on. Be careful to create useful data that isn't misleading since testing alone does not guarantee correctness (evidence f proof! (a) (2 points) How many distinct business types are there? (b) (2 points) How many businesses are in Indiana (IN)? (c) (3 points) How many more or less businesses does Indiana (IN) have compared to Ohio (OH) and Alaska (AK) combined? (d) (8 points) Which users have visited more than 10 distinct states? The output should be ordered (decreasing) by the number of states users visited, where any ties are broken by the user ID (increasing order). Each outputted user should show the ID, name and number of visited states (e) (6 points) How many businesses in Indiana have the word "corn" in their name, but are not identi- fied as a "food" business? Your result should be ordered by business ID and give the ID and name only (f) (10 points) What are the top 5 businesses in West Lafayette, Indiana for dinner (i.e., business type is "dinner")? For this question you will use the average star rating as a measure of quality, where higher number of stars is better. Sort the results by their average rating, breaking any ties by the number of reviews received (decreasing order), then by business ID (increasing order). The output should contain, for each business its ID, name, average number of stars and total number of reviews (g) (10 points) Which Indiana businesses have more than 20 reviews, and all of them are 5 stars? Order the output by the number of reviews received (decreasing order), and business ID (increasing order). Each business displayed should show its ID, name and number of reviews
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started