-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewYork-Resturants.sql
90 lines (67 loc) · 1.92 KB
/
NewYork-Resturants.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
We have put together a table of restaurants called nomnom and we need your help to answer some questions.
Use the SQL commands you just learned and find the best dinner spots in the city.
Start by getting a feel for the nomnom table:
*/
SELECT *
FROM nomnom;
-- What are the distinct neighborhoods?
SELECT DISTINCT neighborhood
FROM nomnom;
-- What are the distinct cuisine types?
SELECT DISTINCT cuisine
FROM nomnom;
-- Suppose we would like some Chinese takeout. What are our options?
SELECT *
FROM nomnom
WHERE cuisine = 'Chinese';
-- Return all the restaurants with reviews of 4 and above.
SELECT *
FROM nomnom
WHERE reviews >= 4;
-- Suppose Abbi and Ilana want to have a fancy dinner date. Return all the restaurants that are Italian and $$$.
SELECT *
FROM nomnom
WHERE cuisine = 'Italian'
AND price = '$$$';
-- Your coworker Trey can’t remember the exact name of a restaurant he went to but he knows it contains the word ‘meatball’ in it. Can you find it for him using a query?
SELECT *
FROM nomnom
WHERE name LIKE '%meatball%';
/*
Let’s order delivery to the house!
Find all the close by spots in Midtown, Downtown or Chinatown.
(OR can be used more than once)
*/
SELECT *
FROM nomnom
WHERE neighbourhood = 'Midtown'
OR neigbourhood = 'Downtown'
OR neighbourhood = 'Chinatown';
-- Find all the health grade pending restaurants (empty values).
SELECT *
FROM nomnom
WHERE health IS NULL;
-- Create a Top 10 Restaurants Ranking based on reviews.
SELECT *
FROM nomnom
ORDER BY review DESC
LIMIT 10;
/*
Use a CASE statement to change the rating system to:
review > 4.5 is Extraordinary
review > 4 is Excellent
review > 3 is Good
review > 2 is Fair
Everything else is Poor
Don’t forget to rename the new column!
*/
SELECT name,
CASE
WHERE review > 4.5 THEN 'Extraordinary'
WHERE review > 4 THEN 'Excellent'
WHERE review > 3 THEN 'Good'
WHERE review > 2 THEN 'Fair'
ELSE 'Poor'
END AS 'Review'
FROM nomnom;