You are on page 1of 5

Gov

ernmentCol
legeofEngi
neer
ing,
Nagpur
Depar
tmentofComput
erSci
ence&Engi
neer
ing
Pr
act
icalLABManualSol
uti
ons(
2021-
22)
I
VthSemester

Subj
ect
:
DATABASEMANAGEMENTSYSTEM
Br
anch:CSE{DIRECTSECONDYEAR}
Name:Vi
shalSur
eshKeshar
wani Enr
olmentNo.
/Rol
lno.74
Bat
ch:
B4. Subj
ectTeacher
:Pr
of.Pr
iyaKhot
ele

Pr
act
ical
-6
Ai
m:-Tost
udyandexecut
ehav
ingcl
ause
MySQLHAVI
NGCl
ause

Hav
ingCl
auseut
il
izedi
nSQLasacondi
ti
onal
Clausewi
thGROUPBYCl
ause.Thi
s
condi
ti
onal
clauser
etur
nsr
owswher
eaggr
egat
efunct
ionr
esul
tsmat
chedwi
thgi
ven
condi
ti
onsonl
y.I
taddedi
ntheSQLbecauseWHERECl
ausecannotbecombi
nedwi
th
aggr
egat
eresul
ts,
soi
thasadi
ff
erentpur
pose.Thepr
imar
ypur
poseoft
heWHERE
Cl
ausei
stodeal
wit
hnon-
aggr
egat
edori
ndi
vi
dual
recor
ds.
 HAVI
NGCl
auseal
way
sut
il
izedi
ncombi
nat
ionwi
thGROUPBYCl
ause.
 HAVI
NGCl
auser
est
ri
ctst
hedat
aont
hegr
oupr
ecor
dsr
athert
hani
ndi
vi
dual
r
ecor
ds.
 WHEREandHAVI
NGcanbeusedi
nasi
ngl
equer
y.

Par
amet
ers

 I
nsomecases,
youneedt
ofi
l
ter
out
thei
ndi
vi
dual
recor
ds.
Insuchcases,
youcan use
WHERECl
ause,Wher
easi
not
hercasesy
ouneedt
ofi
l
tert
hegr
oupswi
tht
he
speci
fi
ccondi
ti
on.I
nsuchcases,
youcanuseHAVI
NGCl
ause.
 WHERECl
ausef
il
ter
sther
ecor
dst
upl
eby
tupl
ewhi
l
eHAVI
NGCl
ausef
il
ter
sthe
whol
egr
oup.
 Aquer
ymayhav
ebot
hthecl
auses(WHEREandHAVI
NGCl
ause)
.
8
 Wher
eCl
auseappl
i
edf
ir
standt
henHav
ingCl
ause.
 WHERECl
auser
est
ri
ctsr
ecor
dsbef
oreGROUPBYCl
ause,
wher
easHAVI
NG
Cl
auser
est
ri
ctsgr
oupsaf
terGROUPBYCl
ausear
eper
for
med.

1.WHERECl
ausecanbeut
il
izedwi
thSELECT,
UPDATE,
DELETE,
andI
NSERT,
wher
eas
HAVI
NGcanbeut
il
izedonl
ywi
thSELECTst
atement

I
nabov
eex ample,Tabl
eisgroupedbasedonDeptI
Dcolumnandthesegr
oupedr
ows
f
il
teredusingHAVINGCl ausewi
thcondi
ti
onAVG(Sal
ary
)>3000.

9
(
i)My
SQLHAVI
NGCl
ausewi
thMI
Nfunct
ion

Let
'
stakeat
abl
e"empl
oyees"t
abl
e,havi
ngt
hef
oll
owi
ngdat
a.

Thef
oll
owi
ngexampl
especi
fi
est
hemi
nimumwor
kinghour
sof
theempl
oyeesf
ormt
het
abl
e"empl
oyees"
.

Execut
ethequer
y:

1
1
(
ii
)My
SQLHAVI
NGCl
ausewi
thMAXf
unct
ion

Let
'
stakeat
abl
e"empl
oyees"t
abl
e,havi
ngt
hef
oll
owi
ngdat
a.

Thef
oll
owi
ngexampl
especi
fi
est
hemaxi
mumwor
kinghour
sof
theempl
oyeesf
ormt
het
abl
e"empl
oyees"
.

Execut
ethef
oll
owi
ngquer
y:

1
1
(
ii
i)My
SQLHAVI
NGCl
ausewi
thAVGf
unct
ion

Let
'st
akeat
abl
e"empl
oyees"t
abl
e,hav
ingt
hef
oll
owi
ngdat
a.

Thefol
l
owingexamplespeci
fi
est
heav
eragewor
kinghour
soft
heempl
oyeesf
orm
thet
abl
e"employees"
.

Execut
ethequer
y:

Concl
usi
on:-Hencewesuccessf
ull edt
yexecut ost
udyandexecut
eHAVI
NGcl
ause.

1
1

You might also like