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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
# Day 1: SQL Basics & Advanced SQL Queries

- [x] Complete the SQL Basics course
- [x] Complete the Advanced SQL queries course

# Day 2: Relational Queries

- [x] Complete the Relational Queries course
- [x] Complete the Modifying databases with SQL course

# Day 3: Install Postgres and Complete Tutorials with psql

- [x] Install Homebrew by following instructions listed here
- [x] Install Postgres by following instructions listed here
- [x] Learn the psql command line tool by working through the following tutorials
- [x] complete the tutorial for createdb here
- [x] complete the tutorial for selecting the database here
- [x] complete the tutorial for dropping the database here
- [x] complete the tutorial for create table here
- [x] complete the tutorial for drop table here
- [x] complete the tutorial for schema here
- [x] complete the tutorial for insert here
- [x] complete the tutorial for select here
- [x] complete the tutorial for expressions here
- [x] complete the tutorial for where clause here
- [x] complete the tutorial for and and or operators here
- [x] complete the tutorial for update queries here
- [x] complete the tutorial for delete queries here
- [x] complete the tutorial for the like clause here
- [x] complete the tutorial for the limit clause here
- [x] complete the tutorial for the order by clause here
- [x] complete the tutorial for the group by clause here

# Day 4: Mini Project & Exercises

- [x] Exercises 1-11 in the sql-exercises repo are complete and written to the appropriate file:
- [x] sql/01-create-table-student.sql
- [x] sql/02-create-table-friend.sql
- [x] sql/03-create-table-like.sql
- [x] sql/04-load-table-learner.sql
- [x] sql/05-load-table-friend.sql
- [x] sql/06-load-table-like.sql
- [x] sql/07-query-friends-gabriel.sql
- [x] sql/08-query-likes-grade-two-or-more.sql
- [x] sql/09-mutual-likes.sql
- [x] sql/10-not-liked.sql
- [x] sql/11-liked-but-does-not-like.sql
- [ ] sql/12-find-friends-in-common.sql
- [ ] sql/13-popular-students.sql

# Day 5: Exercises on SQL Bolt

- [x] Complete the SQL Bolt tutorial


# General

- [x] All major features are added via pull requests with a clear description and concise commit messages.
- [x] SQL files are well formatted and readable.
- [x] All the SQL keywords are capitalized.

# Stretch

- [ ] Complete the Codeacademy course on SQL
- [ ] Complete the SQL Zoo quizzes

# SQL Exercises

Exercises to help exercise the SQL muscles.
Expand Down
5 changes: 5 additions & 0 deletions sql/01-create-table-student.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE student (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
grade INTEGER
);
4 changes: 4 additions & 0 deletions sql/02-create-table-friend.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE friend (
id1 INT REFERENCES student(id),
id2 INT REFERENCES student(id)
);
4 changes: 4 additions & 0 deletions sql/02-create-table-friend0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE friend (
id1 INT REFERENCES student(id),
id2 INT REFERENCES student(id)
);
4 changes: 4 additions & 0 deletions sql/02-create-table-friend1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE friend (
id1 INT REFERENCES student(id),
id2 INT REFERENCES student(id)
);
4 changes: 4 additions & 0 deletions sql/03-create-table-like.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE student_like (
liker_id INT REFERENCES student(ID),
likee_id INT REFERENCES student(ID)
);
2 changes: 2 additions & 0 deletions sql/04-load-table-student.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COPY student
FROM '/Users/kamilalambert/Desktop/Projects/sql-exercises/data/students.csv' DELIMITER ',' CSV HEADER;
2 changes: 2 additions & 0 deletions sql/05-load-table-friend.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COPY friend
FROM '/Users/kamilalambert/Desktop/Projects/sql-exercises/data/friends.csv' DELIMITER ',' CSV HEADER;
2 changes: 2 additions & 0 deletions sql/06-load-table-like.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COPY student_like
FROM '/Users/kamilalambert/Desktop/Projects/sql-exercises/data/likes.csv' DELIMITER ',' CSV HEADER;
4 changes: 4 additions & 0 deletions sql/07-query-friends-gabriel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Find the names of all students who are friends with someone named Gabriel.
SELECT b.name FROM friend
JOIN student a ON a.id = friend.id1
JOIN student b ON b.id = friend.id2 WHERE a.name = 'Gabriel';
7 changes: 7 additions & 0 deletions sql/08-query-likes-grade-two-or-more.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- For every student who likes someone 2 or more grades younger than themselves, return that student's name and grade, and the name and grade of the student they like.

SELECT a.name liker_name, a.grade liker_grade, b.name likee_name, b.grade likee_grade
FROM student_like
JOIN student a ON a.id = student_like.liker_id
JOIN student b ON b.id = student_like.likee_id
WHERE (a.grade - b.grade) >= 2;
13 changes: 13 additions & 0 deletions sql/09-mutual-likes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- For every pair of students who both like each other, return the name and grade of both students. Include each pair only once, with the two names in alphabetical order.

SELECT s1.name liker_name, s1.grade liker_grade, s2.name likee_name, s2.grade likee_grade
FROM (
SELECT a.liker_id, a.likee_id
FROM student_like a
JOIN student_like b
ON a.liker_id = b.likee_id AND b.liker_id = a.likee_id
) mutual
JOIN student s1 ON s1.id = mutual.liker_id
JOIN student s2 ON s2.id = mutual.likee_id
WHERE s1.name < s2.name
ORDER BY s1.name ASC;
8 changes: 8 additions & 0 deletions sql/10-not-liked.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Find all students who do not appear in the like table (as a student who likes or is liked) and return their names and grades. Sort by grade, then by name within each grade.

SELECT name, grade FROM student
WHERE id NOT IN
(SELECT likee_id FROM student_like)
AND id NOT IN
(SELECT liker_id FROM student_like)
ORDER BY grade ASC, name ASC;
6 changes: 6 additions & 0 deletions sql/11-liked-but-does-not-like.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- For every situation where student A likes student B, but we have no information about whom B likes (that is, B's id does not appear in the liker_id column of the like table), return A and B's names and grades.

SELECT a.name, a.grade, b.name, b.grade FROM student_like
JOIN student a ON a.id = student_like.liker_id
JOIN student b ON b.id = student_like.likee_id
WHERE b.id NOT IN (SELECT liker_id FROM student_like);