0% found this document useful (0 votes)
14 views5 pages

Groupby

The document shows SQL commands used to create an employee table, insert rows of employee data, and then run aggregation queries on the table grouped by department to summarize total salary, number of employees, average salary, maximum salary, and minimum salary by department.

Uploaded by

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

Groupby

The document shows SQL commands used to create an employee table, insert rows of employee data, and then run aggregation queries on the table grouped by department to summarize total salary, number of employees, average salary, maximum salary, and minimum salary by department.

Uploaded by

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

SQL> create table iotemployee(eno numeric(2),ename varchar2(7),sal numeric(6),dept varchar2(5));

Table created.

SQL> insert into iotemployee values(&eno,'&ename',&sal,'&dept');

Enter value for eno: 1

Enter value for ename: ramesh

Enter value for sal: 10000

Enter value for dept: cse

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(1,'ramesh',10000,'cse')

1 row created.

SQL> /

Enter value for eno: 2

Enter value for ename: mahesh

Enter value for sal: 20000

Enter value for dept: iot

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(2,'mahesh',20000,'iot')

1 row created.

SQL> /

Enter value for eno: 3

Enter value for ename: naresh

Enter value for sal: 30000

Enter value for dept: cse

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(3,'naresh',30000,'cse')


1 row created.

SQL> /

Enter value for eno: 4

Enter value for ename: suresh

Enter value for sal: 40000

Enter value for dept: iot

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(4,'suresh',40000,'iot')

1 row created.

SQL> /

Enter value for eno: 5

Enter value for ename: naresh

Enter value for sal: 50000

Enter value for dept: cse

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(5,'naresh',50000,'cse')

1 row created.

SQL> /

Enter value for eno: 6

Enter value for ename: kamesh

Enter value for sal: 60000

Enter value for dept: iot

old 1: insert into iotemployee values(&eno,'&ename',&sal,'&dept')

new 1: insert into iotemployee values(6,'kamesh',60000,'iot')


1 row created.

SQL> select *from iotemployee;

ENO ENAME SAL DEPT

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

1 ramesh 10000 cse

2 mahesh 20000 iot

3 naresh 30000 cse

4 suresh 40000 iot

5 naresh 50000 cse

6 kamesh 60000 iot

6 rows selected.

SQL> select dept,sum(sal) as sal from iotemployee group by dept;

DEPT SAL

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

cse 90000

iot 120000

SQL> select dept,count(ename) as count from iotemployee group by dept;

DEPT COUNT

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

cse 3

iot 3
SQL> select dept,avg(sal) as salary from iotemployee group by dept;

DEPT SALARY

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

cse 30000

iot 40000

SQL> select dept,max(sal) as salary from iotemployee group by dept;

DEPT SALARY

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

cse 50000

iot 60000

SQL> select dept,min(sal) as salary from iotemployee group by dept;

DEPT SALARY

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

cse 10000

iot 20000

SQL>

You might also like