0% found this document useful (0 votes)
8 views13 pages

DBMS - Assig 1 & 2

The document contains SQL queries and database operations related to account transactions and employee management. It includes creating tables, inserting values, and querying data for various conditions such as withdrawals, deposits, and employee details. Additionally, it outlines entity-relationship diagrams and schemas for different entities like employees, students, and accidents.

Uploaded by

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

DBMS - Assig 1 & 2

The document contains SQL queries and database operations related to account transactions and employee management. It includes creating tables, inserting values, and querying data for various conditions such as withdrawals, deposits, and employee details. Additionally, it outlines entity-relationship diagrams and schemas for different entities like employees, students, and accidents.

Uploaded by

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

Assionmeot 1:

) Table : Accou ot
ANO ANANE ADDRESS

NTO Singh BangBane


(02 Rohom upta Chenna

I03 Au Raza Hydevabad

|04 Rishab) J cun Chennu

I0S Simson ka) Changigaoh.


Table: ToaNAact
DOT
TRNO ANO ACCOUNT TYP£

TOO1 2S00 Withdo 2017-12-2)


103 3000 Deposit 2017-06- G1
T002
T003 10 2 2000 Witdhaw 2017-05- 12

TO04 {o00 Deposit 2017- 10- 22


TO0S 102 12000 Depasit 207- )) -06

E'nstiy we ceated a data base, ard then cocated and inseated values in the
table AcCOUnt amd Toonsact.

) TodisPBay details of al the toaAacbn of TYPE wi'thdvaw foem Tronsatt


Table.
SELECT * FROM
TRANSACT WHERE TYPE Wíthdh aw'
()T© díspBay AN0 and AmoUNt of all depasits ad
withd sawals done,i month
04 'May' 2017 foom table
(oonsact.
SEECT ANO, AroUNt PRO) T
eANSAC WHERE DOT
2017- 0S -Ol' AND 20)7
-0S-31: BETWEeN
Ni) To dlsptay fiost Dot faom toble
Toonsact fos Accouat havisg ANO a J02
SeLECT MIN(D0T) FROM TRANSACT
WIHERE ANO Jo2
(N) To dispBoy ANO, ANAME, AMOUNT, Od
DOT of those eoSm oom
Account and totnda Ct t0bte who ue done
ta0ANCon (ess than 0
Assignment 1

1.

TRNO ANO AMOUNT TYPE DOT


TO01 101 2500.00 Withdraw 2017-12-21
TO03 102 2000.00 Withdravw 2017-05-12
NULL LL ULL NULL

i. ANO AMOUNT
102 2000.00

MIN(DOT)
2017-05-12

ANO ANAME AMOUNT DOT


101 Nirja Singh 2500.00 2017-12-21
103 Ai Raza 3000.00 2017-06-01
102 Rohan Gupta 2000.00 20 17-05-12
103 AliRaza 1000,00 2017-10-22

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'):

vi) SELECT DISTINCT ANO FROM TRANSACT

(v) sEECT ANO ) CoUNT (F), MIN (AMOUNT) FR0M TRANSACT


GROUP BY ANO HAVING COUNT () >1:

(Wl) SELECT COUNT (*) SäN(ANOUNT) PRONM TRANSACT


WHERE DOT <= 2017-10-01':
(2)

ADE nerted t he given values t9 t.


Table: ENPLOVEE
£ODE NAME DESIGI SGIRADE DOJ DOB
vitcoant Executive SO3 2003-03 -23 1930 oi-12
I02 ROvi Hecd-IT SO2
010-02-121931-0-22
l03 Jotm Recepticnist SO3 2009 -06-24 (923-02-24
Azha S02
2009 -08 - ) 984-03-03
18 Po yom CÊO SO1 2004 -i2-29932 -01-i9
Table: SALGRADE
SGRADE SALARY HRA
SO 56000 J8000
S02 32000 12000
SO3 24000 8000

(i) TO dispBay details of al empBoyee in descending oodes af theis


DOT.
SE LECT * CROMn EMPLOY EE ORDER By DoJ
DESC,
) To dispBay NAME avd DES IG of those
epbyees whose GHRADE 0s eithe
S02 o0 S03.
SELECT NAME DESIG ROM EMPLOVEE WHERE SGRADE IN (S02 S03):
ii) To d ispBay NAMÉ, OEslG Pnd S6IRADE 0f those
emp loees who joimed
year 2009.
CE LECT AIAME DES IGN, SGiRADE FROm eMPLOVEE HERE
YEAR (D0T) 2009
(IV) To dispBay au So|RADE, ANNUAL-SALARY
CROm tobte sALGIRAOE
SELECT SG1RADE, SALARY J2 AS
ANNUAL-SALARY, PRON SALGRADE:
(V) T0 dispBay the umteo of emptqyeCA
LU0dtig in each SALGIRADE
foon table f MPLGV EE
Assignment 1

ECODE NAME DESIG SGRADE DOJ DOB


102 Ravi Head-IT S02 20 10-02-12 1987-07-22
105 Ahar GM SO2 2009-08-11 1984-03-03
103 John Receptonist SO3 2009-06-24 1983-02-24
18 Priyam CEO SO1 2004-12-29 1982-01-19
101 Virant Executive SO3 2003-03-23 1980-01-13
NUILL RULL HULL MULL MULL HULL

NAME DESIG
Vikrant Executive
Ravi Head-IT
John Receptionist
Azhar GM

iii NAME DESIG SGRADE


John Receptonist SO3
Azhar GM SO2

SGRADE ANNUAL SALARY


SO1 672000
iSo2 334000
SO3 288000

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

DESIG SALARY HRA


NAME
Executve 24000 8000
Vikrant
Head-IT 32000 12000
Ravi
Receptonist 24000 8000
John
32000 12000
Azhar GM

vi MIN DOJ) MAX DOB


2003-03-23 1987-07-22

vii SGRADE TOTAL COMPENSATION


SO2 44000

IX DISTINCT_SGRADE COUNT
3

X. TOTALSALARY AVERAGE SALARY


112000 37333.3333
(3)
Entity- Rel atinship CER) Dag-20m :
Enites and Attatbute:
( PeDSON sSN, NQme. Gede) Ackdaess, Bioth Daue )
(2) EmpBoyee (ssN Salay, Empfoyee type)
(5) Facty (sSN. Ront)
(4) StuH (sSN, staff POsition)
(5) Student AsSstonce( sSN, Pexent c! Time wOoked, Assistant rype)
(6) Resegvch Assistant
(sSN, Reseasch Pooject)
(7) Teahing AssistatlsSN, Cusest cowse)
(8) Alumnus sSN)
(9DENee (Oegiee Nome, Yeu hanted, mjor depttme nt, ssN)
(0) Student (SSN, Studenttype, Maj08 depatment)
(UD Grooduate student (sSN,
((2)
Degree pTOgoa m)
Undesgsduate Student (ssN, class)
Relahionship:
APeoSON can be
emptoyee,
Alumnus or Student (isa selttoshp)
A employee is ne of
" A stUdent
{facuety, Staf, Student Ass0stnty (is-a oelh
Assistant is e ther a deeqsch aLiS tat oo a onship)
assistot (is-a delaionthip) Teaching
An Au nmUA has one
00 n0oe
AStudernt is Deees
erthe) a qoduate student 0 an
student (is-a oelctfonship) umd esqd duate
SSN
GHesdes

AdcdoesS
Pezson

BirthDote

SSN Saleny
EmpBoyee facutty Ronk
SSN Rexeaolk
Employee
týpe
poojet
Reseast
Assistant
SSN

SSN Staf Staposition


f.
SSN Cusent
CuKSe
Stdgnt Lis-a
Assistame
Teaching
Asststornt
Pecentof Assistont
Time oorted Type
SSN

M has a Alu muA

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).

T customes.mome (6 bonchnome ='abc' (Uepasito5 Arroust)


) Customer who have an aCcout ) Hme Pabd city and balonce
>L0000:

customer-nome (bTanch.city Ahm edabad' n balonce >1DO00 ( Depasito


Account Br0nch)):
(iiy List of all tomch named with thes naximum balonce:

brOnchome, marlbatonce) (Acount):

(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

You might also like