3rd LAB Program
Queries using aggregate functions (COUNT, AVG, MIN, MAX, SUM),Group by, Order
by.
Employee (E_id, E_name, Age, Salary)
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2. Count number of employee names from Employee table
3. Find the Maximum age from Employee table.
4. Find the Minimum age from Employee table.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.
1. ANS
Creating the Employee Table
mysql> CREATE DATABASE COMPANY03;
mysql> USE COMPANY03;
mysql> CREATE TABLE Employee (
-> E_id INT PRIMARY KEY,
-> E_name VARCHAR(255),
-> Age INT,
-> Salary DECIMAL(10, 2)
-> );
mysql> DESC Employee;
Populating the Employee Table with 12 Records
2. ANS
Count Number of Employee Names
mysql> SELECT COUNT(E_name) AS TotalEmployees
-> FROM Employee;
3. ANS
Find the Maximum Age
mysql> SELECT MAX(Age) AS MaxAge
-> FROM Employee;
4. ANS
Find the Minimum Age
mysql> SELECT MIN(Age) AS MinAge
-> FROM Employee;
5. ANS
Find Salaries of Employees in Ascending Order
mysql> SELECT E_name, Salary
-> FROM Employee
-> ORDER BY Salary ASC;
6. ANS
Find Grouped Salaries of Employees
mysql> SELECT Salary, COUNT(*) AS EmployeeCount
-> FROM Employee
-> GROUP BY Salary;