1. Employees Table

Table: Employees

EmployeeIDNameDepartmentSalaryJoiningDate
1John SmithIT600002018-01-15
2Jane DoeHR750002019-02-20
3Alice BrownIT800002020-03-10
4Bob WhiteFinance500002017-04-25

Question:

Find the highest salary in each department.

SQL Query:

SELECT Department, MAX(Salary) AS HighestSalary
FROM Employees
GROUP BY Department;

2. Orders Table

Table: Orders

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

Question:

Retrieve the total amount spent by each customer.

SQL Query:

SELECT CustomerID, SUM(Amount) AS TotalSpent
FROM Orders
GROUP BY CustomerID;

3. Sales Table

Table: Sales

SaleIDProductIDQuantitySaleDatePrice
1200132022-11-05150
2200222022-11-10200
3200152022-11-15150
4200312022-11-20300

Question:

Calculate the total revenue generated by each product.

SQL Query:

SELECT ProductID, SUM(Quantity * Price) AS TotalRevenue
FROM Sales
GROUP BY ProductID;

4. Students Table

Table: Students

StudentIDNameAgeGrade
1Emma20A
2Liam21B
3Olivia22A
4Noah23C

Question:

Find the average age of students with grade 'A'.

SQL Query:

SELECT AVG(Age) AS AverageAge
FROM Students
WHERE Grade = 'A';

5. Products Table

Table: Products

ProductIDProductNameCategoryPrice
1LaptopElectronics800
2HeadphonesElectronics50
3Coffee MakerHome Appliances120
4MixerHome Appliances150

Question:

List the products with a price higher than the average price of all products.

SQL Query:

SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

6. Customers Table

Table: Customers

CustomerIDNameCountryAge
1Michael ScottUSA45
2Jim HalpertCanada35
3Dwight SchruteUSA40
4Pam BeeslyUK38

Question:

Find the youngest customer in each country.

SQL Query:

SELECT Country, MIN(Age) AS YoungestAge
FROM Customers
GROUP BY Country;

7. Attendance Table

Table: Attendance

StudentIDClassDateStatus
12023-01-10pre style="font-size: 18px;" style="font-size: 18px;"sent
22023-01-10Absent
12023-01-11Absent
22023-01-11pre style="font-size: 18px;" style="font-size: 18px;"sent

Question:

Count the number of days each student was pre style="font-size: 18px;" style="font-size: 18px;"sent.

SQL Query:

SELECT StudentID, COUNT(*) AS Dayspre style="font-size: 18px;" style="font-size: 18px;"sent
FROM Attendance
WHERE Status = 'pre style="font-size: 18px;" style="font-size: 18px;"sent'
GROUP BY StudentID;

8. Inventory Table

Table: Inventory

ItemIDItemNameQuantityPrice
1Notebook505.00
2Pen1001.00
3Pencil750.50
4Eraser300.25

Question:

Find the total value of inventory.

SQL Query:

SELECT SUM(Quantity * Price) AS TotalInventoryValue
FROM Inventory;

9. Books Table

Table: Books

BookIDTitleAuthorPrice
1The AlchemistPaulo Coelho10.00
21984George Orwell8.00
3To Kill a MockingbirdHarper Lee12.00
4The Great GatsbyF. Scott Fitzgerald15.00

Question:

List books priced higher than the average price of all books.

SQL Query:

SELECT Title, Price
FROM Books
WHERE Price > (SELECT AVG(Price) FROM Books);

10. Transactions Table

Table: Transactions

TransactionIDAccountIDAmountTransactionDate
11001500.002023-02-10
21002150.002023-02-12
31001250.002023-02-15
41003300.002023-02-20

Question:

Calculate the total amount transacted by each account.

SQL Query:

SELECT AccountID, SUM(Amount) AS TotalAmount
FROM Transactions
GROUP BY AccountID;