Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added day1.db
Binary file not shown.
58 changes: 58 additions & 0 deletions day1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Show all albums.
SELECT * FROM album;

-- Show all albums made between 1975 and 1990.
SELECT * FROM album
WHERE (release_year <= 1990)
AND (release_year >= 1975);

-- Show all albums whose names start with `Super D`.
SELECT * FROM album
WHERE title LIKE "Super D%";

-- Show all albums that have no release year.
SELECT * FROM album
WHERE release_year IS NULL;


-- Show all track titles from `Super Funky Album`.

SELECT track.title FROM track,album
WHERE album.title = 'Super Funky Album'
AND album_id = album.id;

-- Same query as above, but rename the column from `title` to `Track_Title` in the output.

SELECT track.title AS Track_Title
FROM track,album
WHERE album.title = 'Super Funky Album'
AND album_id = album.id

-- Select all album titles by `Han Solo`.
AND artist.name= 'Han Solo';

SELECT * FROM artist, artist_album
WHERE artist.id = artist_id

-- Select the average year all albums were released.
SELECT avg(release_year)
FROM album;

-- Select the average year all albums by `Leia and the Ewoks` were released.

SELECT AVG(release_year)
FROM artist, album, artist_album
WHERE artist.id = artist_album.artist_id
AND album.id = artist_album.album_id
AND artist.name = 'Leia and the Ewoks';

-- Select the number of artists

SELECT count(id)
FROM artist;

-- Select the number of tracks on `Super Dubstep Album`.

SELECT count(track.id)
FROM track, album
WHERE album.title = "Super Dubstep Album";
Binary file added notes.db
Binary file not shown.
45 changes: 45 additions & 0 deletions notes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Create a database for taking notes.

PRAGMA foreign_keys = ON;

CREATE TABLE author(
id INTEGER PRIMARY KEY AUTOINCREMENT,
author_name VARCHAR(64) NOT NULL
);

CREATE TABLE note (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHER(128) NOT NULL,
content VARCHAR(2056) NOT NULL,
author_id INTEGER REFERENCES author(id),
timestamp DATE DEFAULT (datetime('now', 'localtime'))
FOREIGN KEY(author_id) REFERENCES author(id) ON DELETE CASCADE
);

INSERT INTO author (author_name) VALUES ("David Loveday");
INSERT INTO author (author_name) VALUES ("Mcbed Abed");
INSERT INTO author (author_name) VALUES ("John Medina");
INSERT INTO author (author_name) VALUES ("Joseph Alagoa");

INSERT INTO note (title, content, author_id) VALUES ("Note by David", "This is a note by David", 1);
INSERT INTO note (title, content, author_id) VALUES("Note by Mcbed", "This is a note by Mcbed", 2);
INSERT INTO note (title, content, author_id) VALUES("Note by John", "This is a note by John", 3);
INSERT INTO note (title, content, author_id) VALUES("Note by Joseph", "This is a note by Joseph", 4);
INSERT INTO note (title, content, author_id) VALUES("Another by John", "This is a note by John", 3);
INSERT INTO note (title, content, author_id) VALUES("Another by David", "This is another note by David", 1);
INSERT INTO note (title, content, author_id) VALUES("Another by Mcbed", "This is another note by Mcbed", 2);

SELECT author_name, title, content, timestamp FROM note, author
WHERE author.author_name = "Mcbed Abed"
AND author.id = author_id;

SELECT author.author_name FROM author, note
WHERE note.id = 3 and
author.id = author_id;

SELECT author_name, count(title) FROM note, author
WHERE author.id = author_id
GROUP BY author.author_name;

DELETE FROM author
WHERE name = "Note by Mcbed";
21 changes: 21 additions & 0 deletions tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE album (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(128) NOT NULL,
release_year INTEGER
);

CREATE TABLE artist (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(128) NOT NULL
);

CREATE TABLE track (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(128) NOT NULL,
album_id INTEGER REFERENCES album(id)
);

CREATE TABLE artist_album (
artist_id INTEGER REFERENCES artist(id),
album_id INTEGER REFERENCES album(id)
);