-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps1_queries.txt
138 lines (107 loc) · 2.83 KB
/
ps1_queries.txt
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* CS 460/660: Problem Set 1, SQL Programming Problems
*
* Put your name and email address below:
* name:
* email:
*/
/**********************************************************
* REMEMBER: You should include only the SQL commands,
* *NOT* the results that they produce.
**********************************************************/
/*
* Problem 5. Put your SQL command for this problem below.
*/
SELECT name, pob, dob
FROM Person
WHERE name = 'Forest Whitaker'
OR name = 'Cate Blanchett';
/*
* Problem 6. Put your SQL command for this problem below.
*/
SELECT Movie.name, Oscar.year
FROM Movie, Oscar
WHERE movie_id = id
AND Oscar.year > 1989
AND Oscar.year <2000
AND type = 'BEST-PICTURE'
ORDER BY year;
/*
* Problem 7. Put your SQL command for this problem below.
*/
SELECT COUNT(DISTINCT Movie.name)
FROM Person, Actor, Movie
WHERE Person.id = actor_id
AND movie_id = Movie.id
AND pob NOT LIKE '%USA%';
/*
* Problem 8. Put your SQL command for this problem below.
*/
SELECT name, runtime
FROM Movie
WHERE genre LIKE '%N%'
AND runtime = (SELECT MAX(runtime)
FROM Movie
WHERE genre LIKE '%N%');
/*
* Problem 9. Put your SQL command for this problem below.
*/
SELECT Person.name, O1.type, O2.year, O1.year
FROM Person, Oscar AS O1, Oscar AS O2
WHERE Person.id = O1.person_id
AND O1.person_id = O2.person_id
AND O1.type = O2.type
AND O1.year = O2.year + 1;
/*
* Problem 10. Put your SQL command for this problem below.
*/
SELECT Movie.name, COUNT(*)
FROM Movie, Oscar
WHERE Movie.id = movie_id
GROUP BY Movie.id
HAVING COUNT(*) > 2
ORDER BY COUNT(*) DESC
/*
* Problem 11. Put your SQL command for this problem below.
*/
SELECT DISTINCT name, pob
FROM Person, Director
WHERE Person.id = director_id
AND pob LIKE '%France';
/*
* Problem 12. Put your SQL command for this problem below.
*/
SELECT earnings_rank, Movie.name, Oscar.type
FROM Movie LEFT OUTER JOIN Oscar ON Movie.id = movie_id
WHERE earnings_rank<26
ORDER BY earnings_rank;
/*
* Problem 13. Put your SQL command for this problem below.
*/
SELECT COUNT(*)
FROM Movie, Oscar
WHERE type = 'BEST-PICTURE'
AND movie_id = id
AND runtime > (SELECT AVG(runtime)
FROM Movie);
/*
* Problem 14. Put your SQL command for this problem below.
*/
SELECT type, Person.name, Movie.name
FROM Movie, Oscar LEFT OUTER JOIN Person ON person_id = Person.id
WHERE Oscar.year = 2003
AND movie_id = Movie.id
/*
* Problem 15. Put your SQL command for this problem below.
*/
/*
* Problem 16. Put your SQL command for this problem below.
*/
/*
* Problem 17 (required for CS 660 students; optional for CS 460 students).
* Put your SQL command for this problem below.
*/
/*
* Problem 18 (required for CS 660 students; optional for CS 460 students).
* Put your SQL command(s) for this problem below.
*/