diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5ea2573 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/SQL.LetsGetTogether.iml b/.idea/SQL.LetsGetTogether.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/SQL.LetsGetTogether.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a731dc1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 87c8362..0000000 --- a/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# SQL: Let's Get Together - -Given the scenarios, add the the directed queries to the "answers" directory's files. - - -## Introduction to Joins - -Insert the missing parts in the **JOIN** clause to join the two tables **Enrolments** and **Students**, using the **StudentID** field in both tables as the relationship between the two tables. - -``` -SELECT * -FROM Enrolments -LEFT JOIN Students -[insert clause here]; -``` -*(Add your query to the file exercise1.sql)* - -Choose the correct **JOIN** clause to select all records from the two tables where there is a match in both tables. - -``` -SELECT * -FROM Enrolments -[insert clause here] -ON Enrolments.StudentID=Students.StudentID; -``` - -*(Add your query to the file exercise2.sql)* - - -Choose the correct **JOIN** clause to select all the records from the **Students** table plus all the matches in the **Enrolments** table. - - -``` -SELECT * -FROM Enrolments -[insert clause here] -ON Enrolments.StudentID=Students.StudentID; -``` - -*(Add your query to the file exercise3.sql)* - -## Grouping records by Column -List the number of **Students** in each **Country**. - - -*(Add your query to the file exercise4.sql)* - -List the number of **Students** in each **Country**, ordered by the **Country** with the most **Students** first. - - -*(Add your query to the file exercise5.sql)* - - - -List the number of **Students** in each **Country**, ordered by the **Country** with the most **Students** first, where the number of students is greater than 10. - -*(Add your query to the file exercise6.sql)* diff --git a/answers/exercise1.sql b/answers/exercise1.sql index e69de29..b835076 100644 --- a/answers/exercise1.sql +++ b/answers/exercise1.sql @@ -0,0 +1,3 @@ +SELECT * FROM Enrolments e +LEFT JOIN Students s +ON s.Students = e.StudentID; \ No newline at end of file diff --git a/answers/exercise2.sql b/answers/exercise2.sql index e69de29..0507fc0 100644 --- a/answers/exercise2.sql +++ b/answers/exercise2.sql @@ -0,0 +1,4 @@ +SELECT * +FROM Enrolments e +INNER JOIN Students s +ON Enrolments.StudentID=Students.StudentID; \ No newline at end of file diff --git a/answers/exercise3.sql b/answers/exercise3.sql index e69de29..1d40efc 100644 --- a/answers/exercise3.sql +++ b/answers/exercise3.sql @@ -0,0 +1,4 @@ +SELECT * +FROM Enrolments +LEFT JOIN Students +ON Enrolments.StudentID=Students.StudentID; \ No newline at end of file diff --git a/answers/exercise4.sql b/answers/exercise4.sql index e69de29..8fb9994 100644 --- a/answers/exercise4.sql +++ b/answers/exercise4.sql @@ -0,0 +1 @@ +SELECT COUNT(Country) FROM Students GROUP BY Country; diff --git a/answers/exercise5.sql b/answers/exercise5.sql index e69de29..14fea69 100644 --- a/answers/exercise5.sql +++ b/answers/exercise5.sql @@ -0,0 +1 @@ +SELECT COUNT(Country) FROM Students GROUP BY Country ORDER BY COUNT(Country) DESC; \ No newline at end of file diff --git a/answers/exercise6.sql b/answers/exercise6.sql index e69de29..86ca4a3 100644 --- a/answers/exercise6.sql +++ b/answers/exercise6.sql @@ -0,0 +1 @@ +SELECT COUNT(Country) FROM Students GROUP BY Country HAVING COUNT(Country) > 10 ORDER BY COUNT(Country) DESC; \ No newline at end of file