Вы находитесь на странице: 1из 9

SQL> select * from student;

REGNO SNAME CONTACT_NUMBER DNO TOTAL_MARKS


---------- ---------- -------------- ---------- -----------
6001 Akila 67897899 1 450
6002 Abilasha 56787899 1 495
6003 Anithaa 678897899 2 487
6004 balaji 78977899 2 467

SQL> select min(total_marks) from student;

MIN(TOTAL_MARKS)
----------------
450

SQL> select min(total_marks) as Minimum from student;

MINIMUM
----------
450

SQL> select max(total_marks) as Maximum from student;

MAXIMUM
----------
495

SQL> select max(total_marks) as Maximum from student;

MAXIMUM
----------
495

SQL> select max(total_marks) as Maximum from student where dno=1;

MAXIMUM
----------
495

SQL> select avg(total_marks) from student where dno=1;

AVG(TOTAL_MARKS)
----------------
472.5

SQL> select avg(total_marks) from student group by dno;

AVG(TOTAL_MARKS)
----------------
472.5
477

SQL> select avg(total_marks) ,dno from student group by dno;

AVG(TOTAL_MARKS) DNO
---------------- ----------
472.5 1
477 2

SQL> select avg(total_marks) ,dno from student group by dno having dno>2;

no rows selected

SQL> select avg(total_marks) ,dno from student group by dno having dno>1;

AVG(TOTAL_MARKS) DNO
---------------- ----------
477 2

SQL> select avg(total_marks) ,dno from student group by dno where dno>1;
select avg(total_marks) ,dno from student group by dno where dno>1
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> create table studentdetails(regno varchar(10) primary key,sname


varchar(10),contact_number number(12));

Table created.

SQL>
SQL> create table departmentdetails(dno number(12) primary key,dname varchar(10));

Table created.

SQL> alter table studentdetails add dno number(12);

Table altered.

SQL> alter table studentdetails add constraint kgh foreign key(dno) references
departmentdetails(dno);

Table altered.

SQL>
SQL> insert into departmentdetails values(1,'IT');

1 row created.

SQL> insert into departmentdetails values(2,'CSE');

1 row created.

SQL>
SQL> insert into departmentdetails values(3,'EEE');

1 row created.

SQL>
SQL> select * from departmentdetails;

DNO DNAME
---------- ----------
1 IT
2 CSE
3 EEE

SQL> insert into studentdetails values(6001,'Akila',67897899,1);

1 row created.
SQL>
SQL> insert into studentdetails values(6002,'Abilasha',56787899,1);

1 row created.

SQL> insert into studentdetails values(6003,'Anithaa',678897899,2);

1 row created.

SQL>
SQL> insert into studentdetails values(6004,'balaji',78977899,2);

1 row created.

SQL>
SQL> select regno,sname,dname from studentdetails,departmentdetails;

REGNO SNAME DNAME


---------- ---------- ----------
6001 Akila IT
6002 Abilasha IT
6003 Anithaa IT
6004 balaji IT
6001 Akila CSE
6002 Abilasha CSE
6003 Anithaa CSE
6004 balaji CSE
6001 Akila EEE
6002 Abilasha EEE
6003 Anithaa EEE

REGNO SNAME DNAME


---------- ---------- ----------
6004 balaji EEE

12 rows selected.

SQL> select * from studentdetails,departmentdetails;

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6001 Akila 67897899 1 1 IT
6002 Abilasha 56787899 1 1 IT
6003 Anithaa 678897899 2 1 IT
6004 balaji 78977899 2 1 IT
6001 Akila 67897899 1 2 CSE
6002 Abilasha 56787899 1 2 CSE
6003 Anithaa 678897899 2 2 CSE
6004 balaji 78977899 2 2 CSE
6001 Akila 67897899 1 3 EEE
6002 Abilasha 56787899 1 3 EEE
6003 Anithaa 678897899 2 3 EEE

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6004 balaji 78977899 2 3 EEE

12 rows selected.

SQL> select * from faculty;

FID FNAME DNO HOD_ID


---------- ---------- ---------- ----------
10100 Raj 1
10102 kumar 1
10103 Anu 2

SQL> desc faculty;


Name Null? Type
----------------------------------------- -------- ----------------------------
FID NOT NULL NUMBER(5)
FNAME VARCHAR2(10)
DNO NUMBER(12)
HOD_ID NUMBER(5)

SQL> insert into faculty values(10005,'Akila',2,1);

1 row created.

###############UNION################################

SQL> select sname from studentdetails union select fname from faculty;
SNAME
----------
Abilasha
Akila
Anithaa
Anu
Raj
balaji
kumar

7 rows selected.

SQL> select regno from studentdetails union select fname from faculty;

REGNO
----------
6001
6002
6003
6004
Akila
Anu
Raj
kumar

8 rows selected.

##########################UNION ALL###################3

SQL> select regno from studentdetails union all select fname from faculty;

REGNO
----------
6001
6002
6003
6004
Akila
Raj
kumar
Anu

8 rows selected.
SQL> select sname from studentdetails union all select fname from faculty;

SNAME
----------
Akila
Abilasha
Anithaa
balaji
Akila
Raj
kumar
Anu

8 rows selected.

##########################INTERSECT##########################

SQL> select sname from studentdetails intersect select fname from faculty;

SNAME
----------
Akila

#########################MINUS###############################

SQL> select sname from studentdetails minus select fname from faculty;

SNAME
----------
Abilasha
Anithaa
balaji

####################NATURAL JOIN/INNER JOIN#################


SQL> select s.sname,d.dname from studentdetails s,departmentdetails d where
s.dno=d.dno;

SNAME DNAME
---------- ----------
Akila IT
Abilasha IT
Anithaa CSE
balaji CSE

SQL> select studentdetails.sname, departmentdetails.dname from studentdetails


,departmentdetails where studentdetails.dno=departmentdetails.dno;

SNAME DNAME
---------- ----------
Akila IT
Abilasha IT
Anithaa CSE
balaji CSE

SQL> select s.sname,d.dname from studentdetails s inner join departmentdetails d on


s.dno=d.dno;

SNAME DNAME
---------- ----------
Akila IT
Abilasha IT
Anithaa CSE
balaji CSE

SQL> select * from studentdetails s inner join departmentdetails d on s.dno=d.dno;

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6001 Akila 67897899 1 1 IT
6002 Abilasha 56787899 1 1 IT
6003 Anithaa 678897899 2 2 CSE
6004 balaji 78977899 2 2 CSE

##################LEFT JOIN########################

SQL> select * from studentdetails s left join departmentdetails d on s.dno=d.dno;

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6002 Abilasha 56787899 1 1 IT
6001 Akila 67897899 1 1 IT
6004 balaji 78977899 2 2 CSE
6003 Anithaa 678897899 2 2 CSE

SQL> select * from departmentdetails;

DNO DNAME
---------- ----------
1 IT
2 CSE
3 EEE

###########################RIGHT JOIN######################

SQL> select * from studentdetails s right join departmentdetails d on s.dno=d.dno;

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6001 Akila 67897899 1 1 IT
6002 Abilasha 56787899 1 1 IT
6003 Anithaa 678897899 2 2 CSE
6004 balaji 78977899 2 2 CSE
3 EEE

##########################FULL OUTER JOIN###################

SQL> select * from studentdetails s full outer join departmentdetails d on s.dno=d.dno;

REGNO SNAME CONTACT_NUMBER DNO DNO DNAME


---------- ---------- -------------- ---------- ---------- ----------
6001 Akila 67897899 1 1 IT
6002 Abilasha 56787899 1 1 IT
6003 Anithaa 678897899 2 2 CSE
6004 balaji 78977899 2 2 CSE
3 EEE

SQL> spool off;

Вам также может понравиться