-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooks
128 lines (64 loc) · 3.42 KB
/
Books
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
-- I decided to take all of the books on my bookshelf and create a database made up of the different values.
CREATE TABLE books (
id INTEGER PRIMARY KEY auto_increment,
title TEXT,
author TEXT,
genre TEXT,
rating INTEGER
)
INSERT INTO books (title, author, genre, rating)VALUES ("Beautiful Creatures", "Kami Garcia", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("The Assasins Blade", "Sarah J Maas", "Young Adult", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Hush Hush", "Becca Fitzpatrick", "Paranormal", 3);
INSERT INTO books (title, author, genre, rating) VALUES ("Throne of Glass", "Sarah J Maas", "Young Adult", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Silence", "Becca Fitzpatrick", "Paranormal", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Crown of Midnight", "Sarah J Maas", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Queen of Shadows", "Sarah J Maas", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Heir of Fire", "Sarah J Maas", "Young Adult", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Queen of Shadows", "Sarah J Maas", "Young Adult", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Empire of Storms", "Sarah J Maas", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Tower of Dawn", "Sarah J Maas", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Kingdom of Ash", "Sarah J Maas", "Young Adult", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Crescendo", "Becca Fitzpatrick", "Paranormal", 3);
INSERT INTO books (title, author, genre, rating) VALUES ("Finale", "Becca Fitzpatrick", "Paranormal", 5);
INSERT INTO books (title, author, genre, rating) VALUES ("Beautiful Darkness", "Kami Garcia", "Young Adult", 3);
INSERT INTO books (title, author, genre, rating) VALUES ("Beautiful Chaos", "Kami Garcia", "Young Adult", 4);
INSERT INTO books (title, author, genre, rating) VALUES ("Beautiful Redemption", "Kami Garcia", "Young Adult", 5);
SELECT *
FROM books;
--What is the average rating of books by Sarah J Maas?
SELECT AVG(rating)
FROM books
WHERE author = "Sarah J Maas"
--Result populated: 4.5556
--What is the total number of books in the database written by Becca Fitzpatrick?
SELECT COUNT(title) FROM books WHERE author = "Becca Fitzpatrick"
--result populated:4
--Find all books with a rating higher than 3
SELECT title, author
FROM books
WHERE rating >3
-- A customer asks for books that fall under the Young Adult genre.
SELECT title, author
FROM books
WHERE genre = "Young Adult"
-- Some books are being donated. You're told to find the books with ratings less than 4.
SELECT title, author
FROM books
WHERE rating < 4
-- Find books with 'beautiful' in the title.
SELECT title, author
FROM books
WHERE title LIKE '%beautiful%'
--Youre asked to find all of the books written by Sarah J Maas
SELECT title
FROM books
WHERE author = "Sarah J Maas"
--What is avg rating of the books written by Kami Garcia?
SELECT AVG(rating)
FROM books
WHERE author = "Kami Garcia"
--result: 4
--Avg rating of ALL books in database?
SELECT AVG(rating)
FROM books
--result: 4.2353