Sql Query to find Total Salary Age wise where more than two employees exits in Oracle, we are doing following step:-
- Here first we have created one employee table in oracle.
- In that table there are 5 column id, name, age, address and salary.
- Here first we fetch the employee data.
- The GROUP BY statement groups rows that have the same values into summary rows.like we make the group of age.
- Here we are using aggregate functions (COUNT()) with group by to group the result-set by one or more columns.
- Count total salary which have same age and id>2.
Query table :- select * from employee
ID |
NAME |
AGE |
ADDRESS |
SALARY |
1 |
Vinay |
25 |
Delhi |
1500 |
2 |
Pankaj |
23 |
Mumbai |
2000 |
3 |
Ravi |
25 |
Chennai |
6500 |
4 |
Kamal |
27 |
Bhopal |
8500 |
5 |
Mukesh |
22 |
Hyderabad |
4500 |
6 |
Indresh |
24 |
Indore |
10000 |
7 |
Aman |
25 |
Mumbai |
6000 |
To fetch Total Salary Age wise where more than two employees exits :- Select age,sum(salary) As Total_Salary FROM employee GROUP BY age HAVING COUNT(id) > 2;
AGE |
TOTAL_SALARY |
25 |
14000 |