SQL – Practice Activity
Part 1: Setting Up the Database
- Create the following tables in PostgreSQL:
Students
Courses
Enrollments
- Insert initial data into the
Students and Courses tables.
- Connect PostgreSQL to Excel using the ODBC driver.
- Retrieve and display
Students and Courses data in Excel.
Part 2: SQL Queries and Data Manipulation
- Select Data from Tables:
- Write a
SELECT query to display all students.
- Write a
SELECT query to display all courses with more than 3 credits.
- Write a nested
SELECT query to find all students enrolled in the ‘Mathematics’ course.
- Insert Data Using Nested
SELECT:
- Write a query to insert enrollment records for students into the ‘Physics’ course.
- Use a nested
SELECT query to insert records for students in the ‘Biology’ course if they have an ‘A’ grade in ‘Physics’.
- Update Data:
- Write a query to update the age of a specific student.
- Write an
UPDATE query with a nested SELECT to change grades for students in the ‘Mathematics’ course.
- Use of
JOINs:
- Write an
INNER JOIN query to list all students with their enrolled courses.
- Write a
LEFT JOIN query to find students not enrolled in any course.
- Write a
RIGHT JOIN query to list all courses, including those without any students enrolled.
Part 3: Export Data to Excel and Analyze
- Retrieve Data in Excel:
- Import the result sets of the above queries into Excel.
- Visual Analysis:
- Create a dashboard in Excel showing:
- Total number of students.
- Number of courses and total enrollments.
- A bar chart of students in each course.