1. Employees and Departments Tables

Table: Employees

EmployeeIDNameDepartmentIDSalary
1John Smith160000
2Jane Doe275000
3Alice Brown180000
4Bob White350000

Table: Departments

DepartmentIDDepartmentName
1IT
2HR
3Finance

Question: Find the total salary expenditure for each department.

SQL Query:

SELECT d.DepartmentName, SUM(e.Salary) AS TotalSalary
FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID
GROUP BY d.DepartmentName;
    

2. Orders and Customers Tables

Table: Orders

OrderIDCustomerIDOrderDateAmount
11012023-01-10250.50
21022023-01-12150.75
31032023-01-15300.20
41012023-01-20220.10

Table: Customers

CustomerIDNameCountry
101Michael ScottUSA
102Jim HalpertCanada
103Dwight SchruteUSA

Question: Retrieve the total amount spent by each customer, along with their name and country.

SQL Query:

SELECT c.Name, c.Country, SUM(o.Amount) AS TotalSpent
FROM Orders o
JOIN Customers c ON o.CustomerID = c.CustomerID
GROUP BY c.Name, c.Country;
    

3. Products, Sales, and Categories Tables

Table: Products

ProductIDProductNameCategoryIDPrice
1Laptop1800
2Headphones150
3Coffee Maker2120
4Mixer2150

Table: Sales

SaleIDProductIDQuantitySaleDate
1132022-11-05
2222022-11-10
3152022-11-15
4312022-11-20

Table: Categories

CategoryIDCategoryName
1Electronics
2Home Appliances

Question: Calculate the total revenue generated by each category.

SQL Query:

SELECT c.CategoryName, SUM(s.Quantity * p.Price) AS TotalRevenue
FROM Sales s
JOIN Products p ON s.ProductID = p.ProductID
JOIN Categories c ON p.CategoryID = c.CategoryID
GROUP BY c.CategoryName;
    

4. Students, Courses, and Enrollments Tables

Table: Students

StudentIDNameAge
1Emma20
2Liam21
3Olivia22
4Noah23

Table: Courses

CourseIDCourseName
101Mathematics
102Physics
103Chemistry

Table: Enrollments

EnrollmentIDStudentIDCourseID
11101
22102
33103
44101
51102

Question: List the names of students and the courses they are enrolled in.

SQL Query:

SELECT s.Name, c.CourseName
FROM Enrollments e
JOIN Students s ON e.StudentID = s.StudentID
JOIN Courses c ON e.CourseID = c.CourseID;
    

5. Books, Authors, and BookAuthors Tables

Table: Books

BookIDTitlePrice
1The Alchemist15.99
2198412.99
3To Kill a Mockingbird10.99
4Pride and pre style="font-size: 18px;" style="font-size: 18px;"judice8.99

Table: Authors

AuthorIDName
1Paulo Coelho
2George Orwell
3Harper Lee
4Jane Austen

Table: BookAuthors

BookIDAuthorID
11
22
33
44

Question: List the titles of books and their authors.

SQL Query:

SELECT b.Title, a.Name
FROM BookAuthors ba
JOIN Books b ON ba.BookID = b.BookID
JOIN Authors a ON ba.AuthorID = a.AuthorID;