diff --git a/day1.md b/day1.md new file mode 100644 index 0000000..925f142 --- /dev/null +++ b/day1.md @@ -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'; \ No newline at end of file diff --git a/day2.md b/day2.md new file mode 100644 index 0000000..5094c35 --- /dev/null +++ b/day2.md @@ -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. \ No newline at end of file diff --git a/music.db b/music.db new file mode 100644 index 0000000..21771c7 Binary files /dev/null and b/music.db differ diff --git a/notes.db b/notes.db new file mode 100644 index 0000000..be06cb8 Binary files /dev/null and b/notes.db differ diff --git a/test.db b/test.db new file mode 100644 index 0000000..7a5718f Binary files /dev/null and b/test.db differ