DB Exp 1-8
DB Exp 1-8
------------------------------------------------------------
create table customer(cust_no varchar(5),cust_name varchar(15),age numeric,phone
varchar(10));
a)
insert into customer values(1,'A',23,94567);
\d customer;
Table "public.customer"
Column | Type | Modifiers
-----------+-----------------------+-----------
cust_no | character varying(5) |
cust_name | character varying(15) |
age | numeric |
phone | character varying(10) |
d_birth | date |
c)
create table cust_phone as select cust_name,phone from customer;
SELECT 5
d)
e)
\d customer;
Table "public.customer"
Column | Type | Modifiers
-----------+-----------------------+-----------
cust_no | character varying(5) |
cust_name | character varying(25) |
phone | character varying(10) |
d_birth | date
f)
TRUNCATE customer;
g)
Exp 2 constraints
---------------------------------
a)insert into
sales_man(salesman_no,s_name,place,phone)values(101,'ananthu','feroke',8137036211);
insert into
sales_man(salesman_no,s_name,place,phone)values(102,'fariz','chungam',8137036231);
insert into
sales_man(salesman_no,s_name,place,phone)values(103,'anees','chelari',9997036231);
Exp 3
Hospital table
---------------------------------------------------------
A)
insert into hospital values('D001','miya','cardiologist','mbbs',5);
insert into hospital values('D002','john','orthologist','md',4);
B)
select * from hospital;
doctor_id | doctor_name | department | qualification | experience
-----------+-------------+--------------+---------------+------------
D001 | miya | cardiologist | mbbs | 5
D002 | john | orthologist | md | 4
D003 | ramesh | skin | mbbs | 3
D004 | madona | dentist | bds | 6
D005 | manoj | optometry | md | 1
(5 rows)
C)
select doctor_name from hospital where qualification='md';
doctor_name
-------------
john
manoj
(2 rows)
D)
select doctor_name from hospital where experience>5 and qualification!='md';
doctor_name
-------------
madona
(1 row)
E)
select doctor_name from hospital where department='skin';
doctor_name
-------------
ramesh
(1 row)
G)
delete from hospital where doctor_id='D005';
DELETE 1
select * from hospital;
doctor_id | doctor_name | department | qualification | experience
-----------+-------------+--------------+---------------+------------
D001 | miya | cardiologist | mbbs |5
D002 | john | orthologist | md |4
D004 | madona | dentist | bds |6
D003 | ramesh | skin | mbbs |5
(4 rows)
exp 4 banking database
----------------------------------------------------------------------
create table bank_customer(accno int primary key,customer_name varchar(10),place
varchar(25));
b) select ename,department from employee where age in(select max(age) from employee group
by department);
ename | department
---------+-------------------
vishnus | marketting
basith | sales
sreerag | purchase
infan |sales
department | avg
------------+------------------------
sales | 51333.333333333333
marketting | 15000.0000000000000000
purchase | 30000.000000000000
(3 rows)
e) select min(salary) as min_salary from employee;
select min(salary) as min_salary from employee;
min_salary
------------
2000
(1 row)
f)select count(ename)from employee where department='purchase';
count
-------
1
(1 row)
g)select max(salary)from employee where department='sales';
max
--------
150000
(1 row)
h) select max(salary) - min(salary) as sal_difference from employee;
sal_difference
----------------
148000
(1 row)
select product_name from product where product_name like '_u%' and category='washing
powder';
product_name
--------------
super wash
(1 row)
empname
---------
swathi
vishnu
choilly
(3 rows)
empname | city
---------+------
shreya | usa
(1 row)
f) select cname from works group by cname order by count(*) desc limit 1;
cname
---------
infosys
(1 row)
--------------------------------------------------------
exp 8 supplier-product database
create table supplier(supcode char(4) primary key,sname varchar(20),city varchar(15));
supcode supcode
s1 s4
s3 s6
b)select distinct sname from supplier where supcode in (select supcode from splproduct where
pcode='p2');
sname
-------
kavya
(1 row)
d) select supcode from supplier where city =(select city from supplier where supcode='s1');
supcode
---------
s1
s4
(2 rows)
e)select sname from supplier where supcode in (select supcode from splproduct where
pcode='p1');
sname
----------
musthafa
(1 row)
f) select count (distinct supcode )from splproduct;
count
-------
5
(1 row)
g)select pname,p.pcode,qty from product p join splproduct sp on p.pcode=sp.pcode ;
pname | pcode | qty
-------+-------+-----
pr1 | p1 | 150
pr2 | p2 | 270
pr3 | p3 | 120
pr4 | p4 | 320
pr4 | p4 | 320
(5 rows)