Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Given Queries:-
1.Calculate the total fees obtained by the physicians.Also print the registration number,name and
address of the physician.
2.Find the name of the physicians and there telephone numbers who have visited at least 1
patient.
3.Find the name of the physicians with their telephone numbers whom has been visited by only
patient.
4.Find the names of the patients and their address who have visited to more than one physician.
5.Find the registration number of the physician who has been visited by more than one patient in
the month of November.
6.Find the name and registration number of the physician who has not been visited by any of the
patients.
SQL> INSERT INTO Physician VALUES (P1001 , Asim Mitra , Baranagar , 23438976);
1 row created.
SQL> INSERT INTO Physician VALUES (P1002 , Vikram Singh , Park Circus,
21234567);
1 row created.
SQL> INSERT INTO Physician VALUES (P1003 , S.K.Gupta , Kankurgachi , 27651290);
1 row created.
SQL> INSERT INTO Physician VALUES (P1004 , Aniruddha Roy , Salt lake , 23376721);
1 row created.
SQL> INSERT INTO Physician VALUES (P1005 , Devi Shetty , Alipur , 26753400);
1 row created.
SQL> INSERT INTO Physician VALUES (P1006 , Sougata Basu , Sealdah , 25670911);
1 row created.
ii) SQL> create table Patient
2 ( ptname varchar2(15),
3 ptadd varchar2(20) NOT NULL,
4 PRIMARY KEY(ptname) );
Table Created.
Name Null? Type
----------------------------------------- -------- ------------
PTNAME NOT NULL VARCHAR2(15)
PTADD NOT NULL VARCHAR2(20)
Solution of Queries:-
Query Number 1 :
Calculate the total fees obtained by the physicians.Also print the registration number,name and
address of the physician.
SQL Statement
SQL> select v.phregno REGIS, phname NAME, phadd ADDRESS, sum(feescharged)
TOTAL
2 FEES
3 from Physician p,Visits v
4 where p.phregno=v.phregno
5 group by v.phregno,phname,phadd;
Query Number 2 :
Find the name of the physicians and there telephone numbers who have visited at least 1 patient.
SQL Statement
SQL> select phname,phtelno
2 from Physician
3 where phregno in (select phregno
4 from Visits
5 group by phregno
6 having count(ptname)>=(select count(ptname)
7 from Visits
8 group by(phregno)));
PHNAME PHTELNO
-------------------------- --------------
Asim Mitra 23438967
Vikram Singh 21234567
S.K.Gupta 27651290
Aniruddha Roy 23376721
Devi Shetty 26753400
Query Number 3 :
Find the name of the physicians with their telephone numbers whom has been visited by only
patient.
SQL Statement
SQL> select phname,phtelno,count(v.phregno)
2 from Physician p, Visits v
3 where p.phregno=v.phregno
4 group by phname,phtelno
5 having count(v.phregno)=1;
Query Number 4 :
Find the names of the patients and their address who have visited to more than one physician.
SQL Statement
SQL> select t.ptname,t.ptadd,count(v.phregno)
2 from Patient t, Visits v
3 where t.ptname=v.ptname
4 group by t.ptname,t.ptadd
5 having count(v.phregno) > 1;
Query Number 5 :
Find the registration number of the physician who has been visited by more than one patient in
the month of November.
SQL Statement
SQL> select v.phregno,count(v.ptname)
2 from Visits v, Physician p
3 where p.phregno=v.phregno and
4 to_char(v.date_of_visit, MON)=NOV
5 group by v.phregno
6 having count(v.ptname) > 1;
PHREG COUNT(V.PTNAME)
--------- --------------------------
P1001 2
Query Number 6 :
Find the suppliers who live in the same city as parts.
SQL Statement
SQL> select p.phregno, p.phnname
2 from Physician p
3 where p.phregno not in (select v.phregno
4 from Visits v);