Skip to content

Commit 8d3d1b2

Browse files
committed
add files
1 parent 835b81b commit 8d3d1b2

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
CREATE DATABASE book_library;
2+
USE book_library;
3+
4+
CREATE TABLE authors (
5+
id INT PRIMARY KEY AUTO_INCREMENT,
6+
first_name VARCHAR(30) NOT NULL,
7+
middle_name VARCHAR(30),
8+
last_name VARCHAR(30) NOT NULL,
9+
born DATETIME NOT NULL,
10+
died DATETIME
11+
);
12+
13+
INSERT INTO authors(id,first_name, middle_name, last_name, born, died) VALUES
14+
(1,'Agatha', 'Mary Clarissa','Christie', '1890-09-15', '1976-01-12'),
15+
(2,'William', NULL,'Shakespeare', '1564-04-26', '1616-04-23'),
16+
(3,'Danielle', 'Fernandes Dominique', 'Schuelein-Steel', '1947-07-14', NULL),
17+
(4,'Joanne', NULL,'Rowling' , '1965-07-31', NULL),
18+
(5,'Lev', 'Nikolayevich', 'Tolstoy', '1828-09-09', '1910-11-20'),
19+
(6,'Paulo', 'Coelho de', 'Souza', '1947-08-24', NULL),
20+
(7,'Stephen', 'Edwin', 'King', '1947-09-21', NULL),
21+
(8,'John', 'Ronald Reuel', 'Tolkien', '1892-01-03', '1973-09-02'),
22+
(9,'Erika', NULL, 'Mitchell', '1963-03-07', NULL);
23+
24+
CREATE TABLE books (
25+
id INT PRIMARY KEY AUTO_INCREMENT,
26+
title VARCHAR(100) NOT NULL,
27+
author_id INT NOT NULL,
28+
year_of_release datetime,
29+
cost DOUBLE NOT NULL,
30+
CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES authors(id)
31+
);
32+
33+
INSERT INTO books(author_id,title, year_of_release,cost) VALUES
34+
(1,'Unfinished Portrait', '1930-00-00', 15.99),
35+
(1,'The Mysterious Affair at Styles', '1920-00-00',17.99),
36+
(1,'The Big Four', '1927-00-00',14.99),
37+
(1,'The Murder at the Vicarage', '1930-00-00',13.99),
38+
(1,'The Mystery of the Blue Train', '1928-00-00',12.99),
39+
(2,'Julius Caesar', '1599-00-00',11.99),
40+
(2,'Timon of Athens', '1607-00-00',13.99),
41+
(2,'As You Like It', '1600-00-00',18.99),
42+
(2,'A Midsummer Night\'s Dream', '1595-00-00',15.99),
43+
(3,'Going Home', '1973-00-00',15.99),
44+
(3,'The Ring', '1980-00-00',14.99),
45+
(3,'Secrets', '1985-00-00',15.99),
46+
(3,'Message From Nam', '1990-00-00',13.99),
47+
(4,'Career of Evil', '2015-00-00',15.99),
48+
(4, 'Harry Potter and the Philosopher\'s Stone','1997-00-00',19.99),
49+
(4,'Harry Potter and the Chamber of Secrets','1998-00-00',19.99),
50+
(4,'Harry Potter and the Prisoner of Azkaban','1999-00-00',19.99),
51+
(4,'Harry Potter and the Goblet of Fire','2000-00-00',19.99),
52+
(4,'Harry Potter and the Order of the Phoenix','2003-00-00',19.99),
53+
(4,'Harry Potter and the Half-Blood Prince','2005-00-00',19.99),
54+
(4,'Harry Potter and the Deathly Hallows','2007-00-00',19.99),
55+
(4,'Harry Potter and the Deathly Hallows','2007-00-00',15.99),
56+
(5,'Anna Karenina','1877-00-00',15.99),
57+
(5,'War And Peace','1869-00-00',30),
58+
(5,'Boyhood','1854-00-00',15.99),
59+
(6,'By the River Piedra I Sat Down and Wept','1994-00-00',15.99),
60+
(6,'The Alchemist','1988-00-00',15.99),
61+
(6,'The Fifth Mountain','1996-00-00',15.99),
62+
(6,'The Zahir','2005-00-00',15.99),
63+
(7,'Rage','1977-00-00',13.99),
64+
(7,'The Dead Zone','1979-00-00',13.99),
65+
(7,'It','1986-00-00',13.99),
66+
(7,'It','1986-00-00',13.99),
67+
(8,'The Hobbit','1937-00-00',20.99),
68+
(8,'The Adventures of Tom Bombadil','1962-00-00',13.99),
69+
(9,'Fifty Shades of Grey','2011-00-00',13.99),
70+
(9,'Fifty Shades Darker','2012-00-00',13.99),
71+
(9,'Fifty Shades Freed','2012-00-00',13.99);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- 1.Find Book Titles
2+
SELECT title FROM books
3+
WHERE SUBSTRING(title,1,3) = "The"
4+
ORDER BY `id`;
5+
6+
-- 2.Replace Titles
7+
SELECT REPLACE (`title`,'The','***')
8+
AS 'Title' FROM `books`
9+
WHERE SUBSTRING(title,1,3) = "The"
10+
ORDER BY `id`;
11+
12+
-- 3.Sum Cost of All Books
13+
SELECT SUM(`cost`)
14+
FROM books;
15+
16+
-- 4.Days Lived
17+
SELECT CONCAT(`first_name`,' ',`last_name`) AS 'Full Name',
18+
TIMESTAMPDIFF(DAY,`born`,`died`) AS `Days Lived` FROM `authors`;
19+
20+
-- 5.Harry Potter Books
21+
SELECT title FROM books
22+
WHERE SUBSTRING(title,1,12) = "Harry Potter"
23+
ORDER BY `id`;

0 commit comments

Comments
 (0)