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
42 changes: 42 additions & 0 deletions day1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Write SQL SELECT queries that:

Show all albums.
select * from album;

Show all albums made between 1975 and 1990.
select * from album where release_year between 1975 and 1990;

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;


Write SQL SELECT queries that:

Show all track titles from Super Funky Album.
select track.title from track, album where track.album_id = album.id and album.title = 'Super Funky Album';

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 track.album_id = album.id and album.title = 'Super Funky Album';

Select all album titles by Han Solo.
SELECT album.title FROM album, artist_album, artist WHERE artist_album.album_id = album.id AND artist_album.artist_id = artist.id AND artist.name = "Han Solo";

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 album, artist_album, artist
WHERE artist_album.artist_id = artist.id
AND artist_album.album_id = 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(*) FROM track, album
WHERE track.album_id = album.id
AND album.title = 'Super Dubstep Album';
50 changes: 50 additions & 0 deletions day2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Create a database for taking notes.

* What are the columns that a note table needs?
id, title, body, author, timestamp,

* If you have a timestamp field, how do you auto-populate it with the date?
DATETIME used with GETDATE()

* A note should have a foreign key pointing to an author in an author table.


* What columns are needed for the author table?
id, name,

Write queries that:

* Insert authors to the author table.
insert into author (name) values ('Bob');
insert into author (name) values ('jim');
insert into author (name) values ('jim bob');

* Insert notes to the note table.
insert into note (title, author_id, body) values ("Test note1", 1, "This is a test note!");
insert into note (title, author_id, body) values ("Test note2", 2, "I am your master");
insert into note (title, author_id, body) values ("Test note1", 3, "This jim bob notes");
insert into note (title, author_id, body) values ("Test note1", 1, "This is a test again!");
insert into note (title, author_id, body) values ("Test note1", 1, "This is a test twice!");
insert into note (title, author_id, body) values ("Test note1", 3, "Whos is this possible jim bob");

* Select all notes by an author's name.
select * from note, author where author_id = author.id AND author.name = 'Bob';

* Select author for a particular note by note ID.
select author.name from author, note where note.id = 1;

* Select the names of all the authors along with the number of notes they each have. (Hint: `GROUP BY`.)
select *, count(*) from note group by note.author_id;

* Delete authors from the author table.
> Note that SQLite doesn't enforce foreign key constrains by default. You have
> to enable them by running `PRAGMA foreign_keys = ON;` before your queries.

* What happens when you try to delete an author with an existing note?
it keeps incrementing each time you add in a new value. so instead of starting at a new index its always missing that one anytime you pull records.

* How can you prevent this?
reseed the value

Submit a file `notes.sql` with the queries that build (`CREATE TABLE`/`INSERT`)
and query the database as noted above.
Binary file added music.db
Binary file not shown.
Binary file added notes.db
Binary file not shown.
Binary file added test.db
Binary file not shown.