-
Select all records:
SELECT * FROM Employees;
Output:
ID | Name | Age | Department | Salary ---------------------------------------- 1 | Alice | 30 | HR | 60000 2 | Bob | 25 | IT | 70000 3 | Carol | 27 | IT | 72000 4 | Dave | 35 | Sales | 80000
-
Select specific columns:
SELECT Name, Salary FROM Employees;
Output:
Name | Salary --------------- Alice | 60000 Bob | 70000 Carol | 72000 Dave | 80000
-
Select records with a condition:
SELECT * FROM Employees WHERE Age > 30;
Output:
ID | Name | Age | Department | Salary -------------------------------------- 4 | Dave | 35 | Sales | 80000
-
Insert a new record:
INSERT INTO Employees (ID, Name, Age, Department, Salary) VALUES (5, 'Eve', 28, 'HR', 65000);
Output: (No direct output, but the table will now have an additional record.)
-
Update a record:
UPDATE Employees SET Salary = 75000 WHERE Name = 'Bob';
Output: (No direct output, but Bob's salary will be updated to 75000.)
-
Delete a record:
DELETE FROM Employees WHERE ID = 1;
Output: (No direct output, but the record with ID 1 will be deleted.)
-
Count the number of records:
SELECT COUNT(*) FROM Employees;
Output:
COUNT(*) -------- 4
-
Find the average salary:
SELECT AVG(Salary) FROM Employees;
Output:
AVG(Salary) ------------ 70500
-
Find the maximum salary:
SELECT MAX(Salary) FROM Employees;
Output:
MAX(Salary) ------------ 80000
-
Find the minimum salary:
SELECT MIN(Salary) FROM Employees;
Output:
MIN(Salary) ------------ 60000
-
Group records by department and count:
SELECT Department, COUNT(*) FROM Employees GROUP BY Department;
Output:
Department | COUNT(*) ---------------------- HR | 2 IT | 2 Sales | 1
-
Sort records by salary in descending order:
SELECT * FROM Employees ORDER BY Salary DESC;
Output:
ID | Name | Age | Department | Salary -------------------------------------- 4 | Dave | 35 | Sales | 80000 3 | Carol | 27 | IT | 72000 2 | Bob | 25 | IT | 75000 5 | Eve | 28 | HR | 65000
-
Select records with a salary greater than a certain amount:
SELECT * FROM Employees WHERE Salary > 65000;
Output:
ID | Name | Age | Department | Salary -------------------------------------- 2 | Bob | 25 | IT | 75000 3 | Carol | 27 | IT | 72000 4 | Dave | 35 | Sales | 80000
-
Use DISTINCT to find unique departments:
SELECT DISTINCT Department FROM Employees;
Output:
Department ---------------- HR IT Sales
-
Select records with a specific pattern in a column:
SELECT * FROM Employees WHERE Name LIKE 'A%';
Output:
ID | Name | Age | Department | Salary -------------------------------------- 1 | Alice | 30 | HR | 60000
Created
September 9, 2024 13:06
-
-
Save eeriemyxi/b0135f3facc8c22a8779f0fa29849d6b to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment