Trinh Tong пре 7 година
родитељ
комит
eea4390fb3

+ 68
- 0
src/main/java/io/zipcoder/persistenceapp/model/Person.java Прегледај датотеку

@@ -0,0 +1,68 @@
1
+package io.zipcoder.persistenceapp.model;
2
+
3
+import java.util.Date;
4
+
5
+public class Person {
6
+
7
+    private Long id;
8
+    private String first_name, last_name, mobile;
9
+    private Date birthday;
10
+    private Integer home_ID;
11
+
12
+    public Person() {
13
+    }
14
+
15
+    public Person(Long id, String first_name, String last_name) {
16
+        this.id = id;
17
+        this.first_name = first_name;
18
+        this.last_name = last_name;
19
+    }
20
+
21
+    public Long getId() {
22
+        return id;
23
+    }
24
+
25
+    public void setId(Long id) {
26
+        this.id = id;
27
+    }
28
+
29
+    public String getFirst_name() {
30
+        return first_name;
31
+    }
32
+
33
+    public void setFirst_name(String first_name) {
34
+        this.first_name = first_name;
35
+    }
36
+
37
+    public String getLast_name() {
38
+        return last_name;
39
+    }
40
+
41
+    public void setLast_name(String last_name) {
42
+        this.last_name = last_name;
43
+    }
44
+
45
+    public String getMobile() {
46
+        return mobile;
47
+    }
48
+
49
+    public void setMobile(String mobile) {
50
+        this.mobile = mobile;
51
+    }
52
+
53
+    public Date getBirthday() {
54
+        return birthday;
55
+    }
56
+
57
+    public void setBirthday(Date birthday) {
58
+        this.birthday = birthday;
59
+    }
60
+
61
+    public Integer getHome_ID() {
62
+        return home_ID;
63
+    }
64
+
65
+    public void setHome_ID(Integer home_ID) {
66
+        this.home_ID = home_ID;
67
+    }
68
+}

+ 7
- 0
src/main/java/io/zipcoder/persistenceapp/service/PersonService.java Прегледај датотеку

@@ -0,0 +1,7 @@
1
+package io.zipcoder.persistenceapp.service;
2
+
3
+import org.springframework.stereotype.Service;
4
+
5
+@Service
6
+public class PersonService {
7
+}

+ 26
- 23
src/main/resources/script.sql Прегледај датотеку

@@ -1,28 +1,28 @@
1
-INSERT into movies
1
+INSERT into movies (title, runtime, genre, imdb_score, rating)
2 2
 VALUES ('Howard the Duck', 110, 'Sci-Fi', 4.6, 'PG');
3 3
 
4
-INSERT into movies
4
+INSERT into movies (title, runtime, genre, imdb_score, rating)
5 5
 VALUES ('Lavalantula', 83, 'Horror', 4.7, 'TV-14');
6 6
 
7
-INSERT into movies
7
+INSERT into movies (title, runtime, genre, imdb_score, rating)
8 8
 VALUES ('Starship Troopers', 129, 'Sci-Fi', 7.2, 'PG-13');
9 9
 
10
-INSERT into movies
10
+INSERT into movies (title, runtime, genre, imdb_score, rating)
11 11
 VALUES ('Waltz With Bashir', 90, 'Documentary', 8.0, 'R');
12 12
 
13
-INSERT into movies
13
+INSERT into movies (title, runtime, genre, imdb_score, rating)
14 14
 VALUES ('Spaceballs', 96, 'Comedy', 7.1, 'PG');
15 15
 
16
-INSERT into movies
16
+INSERT into movies (title, runtime, genre, imdb_score, rating)
17 17
 VALUES ('Monsters Inc.', 92, 'Animation', 8.1, 'G');
18 18
 
19
-INSERT into movies
19
+INSERT into movies (title, runtime, genre, imdb_score, rating)
20 20
 VALUES ('Finding Nemo', 101, 'Animation', 8.1, 'G');
21 21
 
22
-INSERT into movies
22
+INSERT into movies (title, runtime, genre, imdb_score, rating)
23 23
 VALUES ('Just Go With It', 117, 'Comedy', 6.4, 'PG-13');
24 24
 
25
-INSERT into movies
25
+INSERT into movies (title, runtime, genre, imdb_score, rating)
26 26
 VALUES ('Dodgeball', 117, 'Comedy', 6.7, 'PG-13');
27 27
 
28 28
 SELECT *
@@ -33,33 +33,35 @@ SELECT *
33 33
 FROM movies
34 34
 WHERE imdb_score >= 6.5;
35 35
 
36
-SELECT  *
36
+SELECT *
37 37
 FROM movies
38 38
 WHERE rating = 'G' OR rating = 'PG'
39 39
 AND runtime < 100;
40 40
 
41 41
 -- avg runtimes of movies rated below 7.5, grouped by genre
42
-Select AVG(runtime)
43
-from movies
44
-where rating < 7.5
42
+SELECT AVG(runtime)
43
+FROM movies
44
+WHERE rating < 7.5
45 45
 GROUP BY genre;
46 46
 
47
-Update movies
48
-Set rating = 'R'
47
+UPDATE movies
48
+SET rating = 'R'
49 49
 WHERE title = 'Starship Troopers';
50 50
 
51
-Select id, rating, title
51
+SELECT id, rating, title
52 52
 FROM movies
53
-Where Genre = 'Horror' AND Genre = 'Documentary';
53
+WHERE Genre = 'Horror' AND Genre = 'Documentary';
54 54
 
55 55
 -- avg min max IMBD score for movies of each rating
56
-Select MIN(imdb_score), MAX(imbd_score), AVG(imbd_score)
57
-from movies
58
-having count(*) > 1;
59
-
60
-
56
+SELECT rating, MIN(imdb_score) as "MIN IMDB SCORE", MAX(imdb_score) as "MAX IMDB SCORE", ROUND(AVG(imdb_score), 2) as "AVG IMDB SCORE", COUNT(*) as "NUM MOVIES"
57
+FROM movies
58
+GROUP BY rating;
61 59
 
60
+-- Use HAVING COUNT(*) > 1
61
+SELECT rating, MIN(imdb_score) as "MIN IMDB SCORE", MAX(imdb_score) as "MAX IMDB SCORE", ROUND(AVG(imdb_score), 2) as "AVG IMDB SCORE"
62
+FROM movies
63
+GROUP BY rating
64
+HAVING count(*) > 1;
62 65
 
63
-Delete from movies
66
+DELETE FROM movies
64 67
 WHERE rating = 'R';