0% found this document useful (0 votes)
7 views

Program 3

The document outlines a program for querying an Employee database using aggregate functions and SQL commands. It includes creating an Employee table with fields for ID, name, age, and salary, as well as various queries to count employee names, find maximum and minimum ages, order salaries, and group salaries. The SQL commands for each operation are provided as examples.

Uploaded by

Impana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Program 3

The document outlines a program for querying an Employee database using aggregate functions and SQL commands. It includes creating an Employee table with fields for ID, name, age, and salary, as well as various queries to count employee names, find maximum and minimum ages, order salaries, and group salaries. The SQL commands for each operation are provided as examples.

Uploaded by

Impana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 3

Queries using aggregate functions (COUNT, AVG, MIN, MAX, SUM), Group by,
Orderby.
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. Create Employee table containing all Records E_id, E_name, Age, Salary.
CREATE TABLE Employee (
E_id INT PRIMARY KEY,
E_name VARCHAR(50),
Age INT,
Salary DECIMAL(10, 2)
);

INSERT INTO Employee (E_id, E_name, Age, Salary) VALUES


(1, 'John', 30, 50000),
(2, 'Alice', 28, 45000),
(3, 'Bob', 35, 60000),
(4, 'Carol', 32, 55000),
(5, 'David', 25, 40000);

2. Count number of employee names from employee table


SELECT COUNT(E_name) AS num_employees FROM Employee;
3. Find the Maximum age from employee table.
SELECT MAX(Age) AS max_age FROM Employee;

4. Find the Minimum age from employee table.


SELECT MIN(Age) AS min_age FROM Employee;

5. Find salaries of employee in Ascending Order.


SELECT Salary FROM Employee ORDER BY Salary ASC;

6. Find grouped salaries of employees.


SELECT Salary, COUNT(*) AS num_employees_with_salary FROM Employee
GROUP BY Salary;

You might also like