EmployeeID | Name | Department | Salary | JoiningDate |
---|---|---|---|---|
1 | John Smith | IT | 60000 | 2018-01-15 |
2 | Jane Doe | HR | 75000 | 2019-02-20 |
3 | Alice Brown | IT | 80000 | 2020-03-10 |
4 | Bob White | Finance | 50000 | 2017-04-25 |
Find the highest salary in each department.
SELECT Department, MAX(Salary) AS HighestSalary FROM Employees GROUP BY Department;
OrderID | CustomerID | OrderDate | Amount |
---|---|---|---|
1 | 101 | 2023-01-10 | 250.50 |
2 | 102 | 2023-01-12 | 150.75 |
3 | 103 | 2023-01-15 | 300.20 |
4 | 101 | 2023-01-20 | 220.10 |
Retrieve the total amount spent by each customer.
SELECT CustomerID, SUM(Amount) AS TotalSpent FROM Orders GROUP BY CustomerID;
SaleID | ProductID | Quantity | SaleDate | Price |
---|---|---|---|---|
1 | 2001 | 3 | 2022-11-05 | 150 |
2 | 2002 | 2 | 2022-11-10 | 200 |
3 | 2001 | 5 | 2022-11-15 | 150 |
4 | 2003 | 1 | 2022-11-20 | 300 |
Calculate the total revenue generated by each product.
SELECT ProductID, SUM(Quantity * Price) AS TotalRevenue FROM Sales GROUP BY ProductID;
StudentID | Name | Age | Grade |
---|---|---|---|
1 | Emma | 20 | A |
2 | Liam | 21 | B |
3 | Olivia | 22 | A |
4 | Noah | 23 | C |
Find the average age of students with grade 'A'.
SELECT AVG(Age) AS AverageAge FROM Students WHERE Grade = 'A';
ProductID | ProductName | Category | Price |
---|---|---|---|
1 | Laptop | Electronics | 800 |
2 | Headphones | Electronics | 50 |
3 | Coffee Maker | Home Appliances | 120 |
4 | Mixer | Home Appliances | 150 |
List the products with a price higher than the average price of all products.
SELECT ProductName, Price FROM Products WHERE Price > (SELECT AVG(Price) FROM Products);
CustomerID | Name | Country | Age |
---|---|---|---|
1 | Michael Scott | USA | 45 |
2 | Jim Halpert | Canada | 35 |
3 | Dwight Schrute | USA | 40 |
4 | Pam Beesly | UK | 38 |
Find the youngest customer in each country.
SELECT Country, MIN(Age) AS YoungestAge FROM Customers GROUP BY Country;
StudentID | ClassDate | Status |
---|---|---|
1 | 2023-01-10 | pre style="font-size: 18px;" style="font-size: 18px;"sent |
2 | 2023-01-10 | Absent |
1 | 2023-01-11 | Absent |
2 | 2023-01-11 | pre style="font-size: 18px;" style="font-size: 18px;"sent |
Count the number of days each student was pre style="font-size: 18px;" style="font-size: 18px;"sent.
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;
ItemID | ItemName | Quantity | Price |
---|---|---|---|
1 | Notebook | 50 | 5.00 |
2 | Pen | 100 | 1.00 |
3 | Pencil | 75 | 0.50 |
4 | Eraser | 30 | 0.25 |
Find the total value of inventory.
SELECT SUM(Quantity * Price) AS TotalInventoryValue FROM Inventory;
BookID | Title | Author | Price |
---|---|---|---|
1 | The Alchemist | Paulo Coelho | 10.00 |
2 | 1984 | George Orwell | 8.00 |
3 | To Kill a Mockingbird | Harper Lee | 12.00 |
4 | The Great Gatsby | F. Scott Fitzgerald | 15.00 |
List books priced higher than the average price of all books.
SELECT Title, Price FROM Books WHERE Price > (SELECT AVG(Price) FROM Books);
TransactionID | AccountID | Amount | TransactionDate |
---|---|---|---|
1 | 1001 | 500.00 | 2023-02-10 |
2 | 1002 | 150.00 | 2023-02-12 |
3 | 1001 | 250.00 | 2023-02-15 |
4 | 1003 | 300.00 | 2023-02-20 |
Calculate the total amount transacted by each account.
SELECT AccountID, SUM(Amount) AS TotalAmount FROM Transactions GROUP BY AccountID;