DBMS - Assig 1 & 2
DBMS - Assig 1 & 2
) Table : Accou ot
ANO ANANE ADDRESS
E'nstiy we ceated a data base, ard then cocated and inseated values in the
table AcCOUnt amd Toonsact.
1.
i. ANO AMOUNT
102 2000.00
MIN(DOT)
2017-05-12
V. ANAME
ANO
103 Ai Raza
105 Simran Kaur
NULL NULL
vi ANO
101
102
103
vii.
ANO COUNT() MIN(AMOUNT)
102 2 2000.00
103 2 1000.00
Vi.
COUNT() sUM(AMOUNT)
2 5000.00
9ual to 3000.
A.ANAME, T AMOUNT 1-DO
SELECT AANO,
TRANSACT AS T ON D. N0 ANO WHERE TAMOUNTC3000
FROM AcCoUNT
() SELECT ANO, ANIAME
WHERE ADDRESS NOT IN ('CHÊNNA1, BANG AORE'):
NAME DESIG
Vikrant Executive
Ravi Head-IT
John Receptionist
Azhar GM
V.
SGRADE EMPLOYEE COUNT
SO1
So3 2
S02
SELECT SGRADE (OUNT (*) AS
SsRADE: ENPLOYEE COUNT CROM CMPLOVEE GR0UPp By
(vi) To dispfay
NAME, DESIGt, SALARY, HRA foom
Salgade. {able Cmptouec
emptoyee
0nc|
SEIECT EMALOVEE. NAME
EMPLOYEE. DISG,
SALGRADE. SG RADE IIHERE SALGRDE ON ENMMPLOYEE. SALARY,
HRA cRON
EMPLOVEE JOlN
SAgoADE
ÊMPLOYEE. SG1RADE
(VI) To
SALGIRADE. SAARY < SOO00,
Selec the MIN OJ aod
MAx Me focm
SELECT MIN(DOT) AS
MINDOJ,
EPLOYÉE tase
MHX DOB) AS
vi) To select MAX-DOB FROM EMPLOygE
sGiRADE ad
where SGRADE = (S02 to tal C¡mpenation (salayt HRA) o¡m SALGRDE
SELECT SGRADE SALARY + HRA AS
ALGRADE WHERE SGRADE
Cx) To Count the
S02: TOTAL-OMPENSATION FROM
distinct
numbe of SGIRADE in
SELECT COUNT (DISTINCT
SGIRADE) AS EMpLOV EE Table
EMPLOy EE; OIsTINT_SGRADE_COUNT FRONM
(X) To calculate the
sum and avera9e saly
SELECT SUM(SALARV) AS focm SALGRADE table.
SALARy PROM SALGRADE:TOTAL-SALARY, AVG(SALARY) AS AVERAGIE.
Assignment 1
IX DISTINCT_SGRADE COUNT
3
AdcdoesS
Pezson
BirthDote
SSN Saleny
EmpBoyee facutty Ronk
SSN Rexeaolk
Employee
týpe
poojet
Reseast
Assistant
SSN
Yeay Degree
grafted Narne
SSN
Degree
Student Studet
is4
/Majco SSN type
Depastmet majo
defatmed
CSN
6roaduote (odeogoc
Swent
Oeglee
pdoyiom cBass
Assinment 2:
(4) schema: ne boanch city)
8omch (banch nme,
Acount( baonct. nome, aCC-N0, balance)
Deposito7 ( eatomet. Mae, 0cc-mo).
(2) Table:
Peoscn (sS# »nome, addess)
Car license. yea, mode)
Accidentdate, dzivel, damageaccount )
OwnssStt, licee)
Log liicense, date, ive)
9 Fnd the total numbex of peo ple who cas weoe inuolve sn accidet in 209
SELECT COUNT (DISTINCT O.SS#)
Foo Owns AS o
JoIN LOq 1 ON o. license = .ficenAe
JOIN Accident aA a ON 4.ficenae = a diNe
WHCRE YEAR (a. date)= 2009:
(1) Find the numtex of
"'S- Sudashan":
actidents in which the ca betongng to
SELECT COUNT L*)
FROM ACcideat AS a
JOIN L0g AS ! ON a diver =.d oiVer
JOIN Owns AS 0 ON isene o. licene
JOIN PeasoN ASP oN O. Sst = p. Ss)
WHERE p. n0me
a neU CUAtmes to the dataake
(0)) Add
JNSERT INTO Peso
sstt, name olelaess) vALUES I'2345
'Bhopal):
'Koitik
cy) Aid a new acident oecoied f the Sont0belonging to "kogu!.
TNSERT IND ACCident (daBe, dove, dormoge ommunt)
SELECT 202S -02-20 l.daiver. 5000
FROM tog As l
JOIN Owns AS o ON d ticeme= oicenae
JOIN Ca AS C ON O. license c ticee
WHERE C model SANTRO AND O. SS# IN (SELECT sS# fROM
PeTSm cohere gme= IcORH'}
(3) Tables:
Author (id, name, bithyean, deadth- yea)
Book (id, uthor id titte, Push. yeal, Publishishing-houe )
Adaptathion (book. id, type, title, efease_ye, dating)
Bookoview (book Id, Devie), autho)
a) Show each author's name with
the book titte qod publtcCbtn
yeas
SELECT 0.n0me, btte, b PubliSh yeas
FROM Authos AS a
JON Boob As b ON a.jd =
b-uthov id;
(1) Shouw books uith adaptatin detarts, ictuding those
4 yes and with a lowes vahing:
adapted with
SELECT btitte, a. titte, AS adap tahion title
Yeas FROM Book AS t a-elecse_veA, bpublish
J0IN Ad aptatom aa ON bid =ab¡okid
WHERE arang (SELECT AVG (0Cting ) PRoM Adapthon)
AID adeleeyeade-- Publishyea 4
) Stouw all the took with thei
with vo adaptation movie adaptatoN, keepnq bookS
SELE CT btitte b- publishing-house coA LESCE ( a.title,
AS No adapta
adaptation -tite , a type
FROM Bcok As t
have (al Hoks 8-C ?
diftexent ue(al kaho otdoes AB-C? "
B’C and AB’C (C)
B3, also
b2 and b2d2 (as b):X
ho
b)dOeANt
it
holda) difteent. ase (All deteomines
C? uey Unig AB
B’D and ’C AB(b)
asd di (al H?X ceeonmine uely uDig .
hold) doedot ’d2, ataso
y) ase alt deteTMiNe uely unig "AB
, (al+1 D?v
d!
DA and A8’D (a)
d3 CA b3 a3
d3 (2 b2 a2
d2 C2 be
di b1
B
oela'on istance
of anGiven 5)
C,DRA,B,
)
{P.S.U}P
{P.RR
{P.RY’p
dependencies: funchion
al Toivial
6P.SU’R
fPsu}Q
includes: of
E+Ctosuse
T.U) R,S, X(P.a,
dependeiesDN: funchonl (4)
Adaptah¡n JOJN LECT
bootd; a- =id b. ON aAS
and A’D
(d A8D
have ungue vole)
al
AB-D? Holds ( y ql’ d! and ald2)
told (
AD? does)t
AB-Cond A’D
(e)
Holds (AIlae diHeent)
AB-C2