Sie sind auf Seite 1von 7

EMPLOYEE ( EMP_ID, NAME, DEPT_NAME, SALARY) Salary should be given with decimal places.

Ans)SQL> CREATE TABLE EMPLOYEE ( EMP_ID integer primary key, NAME varchar(50), DEPT_N

AME varchar(30), SALARY number(10,2));

Table created.

SQL> insert into employee values(101,'prudhvi','biology',6000);

1 row created.

SQL> insert into employee values(102,'sravan','physics',7000);

1 row created.

SQL> insert into employee values(103,'Sai kalyan','CSE',9000);

1 row created.

SQL> insert into employee values(104,'hari Krishna.','cse',5000);

1 row created.

SQL> insert into employee values(105,'adithya','english',8000);

1 row created.
Queries: 1. Find the sum of all salaries in the organization.

Ans)35000

SQL> select sum(salary) from employee;

SUM(SALARY)

-----------

2. Find the sum of the salaries grouped by dept.

Ans)

SQL> select dept_name,sum(salary) from employee group by(dept_name);

DEPT_NAME SUM(SALARY)

'biology' ,6000);

'physics', 7000

Cse 9000

Cse 5000

english 8000

3. Find the sum of the salaries for a particular department.

Ans)

SQL> select sum(salary) from employee where dept_name='cse';

SUM(SALARY)
-----------

14000

4. Calculate the average of all the salaries in the organization.

Ans)

SQL> select avg(salary) from employee;

AVG(SALARY)

-----------

7000

5. Find the minimum salary within a particular department.

Ans)

SQL> select min(salary) from employee where dept_name='cse';

MIN(SALARY)

-----------

5000

6. Find the maximum salary within a particular department.

Ans)

SQL> select max(salary) from employee where dept_name='cse';

MAX(SALARY)

-----------

9000

7. Find the total number of employees in each department.


Ans)

SQL> select dept_name,count(*) from employee group by(dept_name);

DEPT_NAME COUNT(*)

------------------------------ ----------

cse 2

physics 1

biology 1

English 1

8. Find the employees who have the salary less than 20000.

Ans)

SQL> select * from employee where salary<20000;

In the above created table all the values are less than 20000

9. Sort the relation with respect to dept_name in ascending order and salary in desc order
within the dept.

Ans)

SQL> select * from employee order by dept_name asc,salary desc;

EMP_ID NAME

---------- --------------------------------------------------

DEPT_NAME SALARY

------------------------------ ----------

harikrishna 5000
'prudhvi' ,6000);

'sravan', 7000

adithya 8000

saikalyan 9000

10.Find the first value of the “NAME” column.

Ans)

SQL> select * from employee where emp_id=(select min(emp_id) from employee);

EMP_ID NAME

---------- --------------------------------------------------

DEPT_NAME SALARY

------------------------------ ----------

101 prudhvi

biology 6000

11.Find the last value of the “NAME” column.

Ans)

SQL> select * from employee where emp_id=(select max(emp_id) from employee);

EMP_ID NAME

---------- --------------------------------------------------

DEPT_NAME SALARY

------------------------------ ----------
105 adithya

english 8000

12.Select the content of the "NAME" and "SALARY" columns from employee table, and convert
the "NAME" column to uppercase.

Ans)

SQL> select upper(name) as name,salary from employee;

NAME SALARY

-------------------------------------------------- ----------

PRUDHVI 6000

SRAVAN 7000

SAI KALYAN 9000

HARIKISHNA 5000

ADITHYA 8000
13.Select the content of the "NAME" and "SALARY" columns from employee table, and convert
the "NAME" column to lowercase.

Ans)

prudhvi 6000

sravan 7000

saikalyan 9000

harikrishna 5000

adithya 8000

SQL> select lower(name) as name,salary from employee;

NAME SALARY

-------------------------------------------------- ----------

14.Select the length of the values in the "DEPT_NAME" column from employee table.
Ans)

SQL> select length(dept_name) from employee;

LENGTH(DEPT_NAME)

-----------------

15. List the departments in which the average salary of the employees is greater than 50,000.

Ans)

SQL> select dept_name from employee group by(dept_name) having avg(salary)>50000

As per the created table the salary are less than 50000

Das könnte Ihnen auch gefallen