DOL Comnands (On Dot Boses:: Database Fundamental$
DOL Comnands (On Dot Boses:: Database Fundamental$
SELECT coumnl
foumh-5)coumn6
sRT( column-3coumn3t cowmn-5
AS PPE-vaue FROM databaenome. table- name
Poce
H D
GROUP BY HAVING SELET DrSTTNT
FROM JOTN WWHERE
ORDERS
adunoexeuhon
DELETE
taggate functiong :
MAX/MIN :
SELECT MAX(olumn) FROM datbase-nome. tade-nor
’ metons the maxímum value omn column-1
simi louy MIN netoins mimum value
AVE:
SELECT AVG (roting) FROM databasename. table-name
wHERE ondname = xiaemi
’ netuinS
wheetheborond-name
auerage uaue o oumn
SUM :
sELECT suM(psuce) FRM dataose-nome, table-nom
’ netnns sum of all uaue tor the ulumn pouce
COUNT:
SELECT CoUNTC*) FRorM databose_name. tabkname
wHERE loand-name = " apple"
GtRouping:GROUp BY)
SELECT botond_name CoUNT (*) As num-o7- phenes
FROM Compusx. Smatphones
GROUP BY bond-name
bxond-na mt
ORDER 8Y num-o-phones DESC Aum-o- fhen
LIMIT5 Ki om 134
Sa msung 132
eg0ind Hhe oug ahing a7 snattphone bonds whch haut mau ton
20 phones.
SELECT lord-ncme,
COUNT (*) AS count!
AuG (9ahing) As 'aug- maing
FROM Cam pusx. Sman tphenes
GRoUP BY brand-name
HAVINÇ Count > 40
oROER SY oug. nahing DE SC
sELECT boordnome, proce S$0- bund (ouT C) AS na phon es,
psunny-comuHa- Hia)) As 'aug comoa otesal uhone
RoUNO (AVG(
FRoM saleohning: smastphenes
qRou eY brandname,pnocei509h-bmand
+ $QL JorNS
Ajoin is a way to combine data otom two on mane dotabase
tables boseol an a nalatad column betoeen ttem
Sels Join
Ctoss Join
Ful Join (outo Join
CROSS JOIN :
CAS)
SELECT FROM databose- nome.tble|
+2
CROSS JOIN database-nome. table2 AS
INNER JoIN :
LEFT JOIN :
sELECTFROM datbosenome.table-1 AS tl
LEFT JOIN databost _name.table. 2 AS +2
ON l. uSMid H2.usrid
RIGHT JoIN
44
4 3 3
Dote
one (oumn
on mone han
Jpining stdents AS t|
StLECT t FROM sqleoning.
closs AS 42
INMER JOIN sqllemning AMD
ON 1. class-id = 42. class-d
enrollment-yean = #2. closr-y<an
Filteung Columns :
Find ondoid name ond city by
joining usou and ordos
sELECT tl.ondonid, 2. name, 2. dty
FROM sqlleahning-ondons tl
30TN sqlac1ning- usens t2
ON t), usu-io
42.usutid
Tind cndenid product
catgony by joining
SELE CT }1.0hden id,2.
eROM uenhcal
salleagining.oxdey-detai
JoTN sqlltaning- cotegony ls+2 t\
ON 1.
categoy-id =
Filteúng Rows
customen Sos to
Tìnd au the omdens placed in lune (aom
Tyges OF Subqucwes
Bosed on :
) The mesult it utuns
Retned Data
Scala kow
sabquey Subquny subqut
hosaoy
iennes
husue 6-1
te manu
iachen 1-6
2 Based on
woniny
tooalated
he innet ot quwwy ane
in dapendat om eoch othe
They an getexcuteo uy cant gt exe tel sepavaltuy
Sepoonately.
Indigendent SubauIS Scalan Subquy
Coseloted Subgquny :
The innot quony can't be esuted seqonately, it nquu
the outin quy ton eKeution
Find all he moli'es that haue a nakng hghn than th
auag ahng of mauiei in the same que
SELECT * FROM molies ml
wHERE SCome >(sELGCT AVG (Scane) pRoM moues m2
wHERE m2.gensu - ml.gnae)
13 74
A
14 14
C c SE 15 14
32
92 $2
ECE 83 82
2 MECH S2
MECH S2
MECH 53 52
Tind all the students who haue mans highen than the aug manl
o theim nespec hiue bnanch
SEE SELECT * FROM sELECT #
3 2
Dgte
SELE CT+
RANK C) oUER (taRTITION 6Y byanch ORDER BY maaks DEsc)
DEAISE-RANK () DUERPARTLIION 8Y branch oROER BY
FROM mAnKS
mas DE
SELECT+
RowNUM6ERC) OU ERARTITION 8Y bhonch
FROM manls
32 2
C 3
3 ECE 64
2
EcE 63 2
MBUM
MECH S 2
S 13
MECH 3
MECH 92 4
sELE CT
LAST-VALUE (mawks ) ouER ORDER 6Y manks DESC
RowS BETWEEN ON BoUNOED
PRECEDING AND UNBOUNOED FoLLOwIE
FROM mcos
NTH_ VALU6 :
SELECT,
NTH- VALO¬ nome, 2) ouER/PARTITTON 8Y bnonch
ORDER 8Y monks DESC
ROws BETWEEN UuROUNDED
PRECEDINE AND UN BOVNOE) PoLLOwDu
FROM mascks
Hhis quuy wiu giue mname o 2n0 tap pem eucny bron
Studentid name banch movs NTH-Ua
CSE B
2 B cSE
3
4 CSE
¬CE
6
¬CE
ECE 10
61 J
MECH S J
MEUY
2 " 44
LAG)
SELECT
LAG (mass) ovER (ORDER8Y studentid
FROM madls
LEAD C)
SELE CT 4
LEAO (madks) oVER(oRDEK BY shudent-id)
FROM maul f
Ranking
Tind MoM qrowth nate aq Zomato
SELE CT MONTHNAME(dote),suM (omount],
tsuM(amount)-LA 4(sum(omount)) au ER (OROER BY MouH(dsy)
FROM o91dens
GROUP BY MOLTHNAME Cdate)
SRDER BY MONTH (dote) ASC
MopTHNAMC(dotu) sunomount)
May 2425 Nul
June 3220 32-1835
4845 So. 465?
Many ee
NVLL
Smi4h MULL
fech al the de aue o the shededs studyingin. an dup
wwhydatment hey a utteYC antnen