Professional Documents
Culture Documents
Base Datos SQL
Base Datos SQL
selectdname,locationfromdepartments
selectename,init,job,msal
fromemployees
wheredeptno=30//muestra6columnassinelwheremuestra10columnas
selectename,init,msalsalary//secambiaelnombreperosoloparaverlo(unnuevotitulo)
fromemployees
wheredeptno=30
selectDISTINCTjob,deptno//eliminarepeticiones
fromemployees
selectgrade,upperlimitlowerlimit//elsignomenosesunarestoentredosvalores
numericos(paraponerunaliasnombrecolumna
espacioyelnombredelalias)
fromsalgrades
selectinit||''||enamename
,12*msalyearsal
fromemployees
wheredeptno=10
selectename,msal,comm,12*msal+comm
fromemployees
whereempno<7600
selectename,init
fromemployees
wherebdate>='1/01/1960'
_____________________________________________________________13/04/16
selectdeptno,ename,init,msal
fromemployees
wheremsal<1500
orderbydeptno,ename
selectename,12*msal+commasyearsal
fromemployees
wherejob='SALESREP'
orderbyyearsaldesc
selectevaluation
fromregistrations
whereattendee=7788
orderbyevaluation
selectevaluation
fromregistrations
whereattendee=7788
orderbyevaluationDESC//valoresnulossinoaparece
selectcode,category,duration
fromcourses
wherecategory='BLD'
orduration=2
selectcode,category,duration
fromcourses
wherecategory='BLD'
ANDduration=2
operadorNOTanteponeunacondicionlainversa
selectename,job,deptno
fromemployees
whereNOTdeptno>10//ejtodoslosquesonigualadiez
selectename,job,deptno
fromemployees
whereNOTdeptno<=10
selectcode,category,duration
fromcourses
where(category='BLD'orduration=2)
andnot(category='BLD'andduration=2)
select*fromemployeeswhereNOT(ename='BLAKE'ANDinit='R')
select*fromemployeeswhereename<>'BLAKE'ORinit<>'R'
selectename,init,msal
fromemployees
wheremsalbetween1300and1600
wheremsalNOTbetween1000and2000
whereNOTmsalbetween1000and2000
wheremsal<1000ORmsal>2000
selectempno,ename
fromemployees
whereempnoin(7499,7566,7788)
select*fromregistrations
whereevaluationNOTIN(3,4,5)
whereNOTevaluationIN(3,4,5)
select*fromregistrations
whereNOT(evaluation=3ORevaluation=4ORevaluation=5)
select*fromcourses
wheredescriptionLIKE'%SQL%'//contengaesoscaracteres0om{ascaracteres
selectempno,init,ename
fromemployees
whereenamelike'_A%'//unsolocaracter
selectattendee,begindate
,caseevaluation
when1then'bad'
when2then'mediocre'
when3then'ok'
when4then'good'
when5then'excellent'
else'notfilledin'
endasnombre
fromregistrations
wherecourse='S02'
selectename,job
,casewhenjob='TRAINER'then'10%'
whenjob='MANAGER'then'20%'
whenename='SMITH'then'30%'
else'0%'
endasraise
fromemployees
orderbyraisedesc,ename
_______________________________________________________18/04/16
selectattendee
fromregistrations
wherecoursein('JAV','PLS','XML')
eslomismoquearribaperoestoesLocorrecto:(condistinctnoserepitenlosvalores)
selectDISTINCTattendee
fromregistrations
wherecoursein(selectcode
fromcourses
wherecategory='BLD')
selectempno,ename,comm
fromemployees
wherecomm>400
selectempno,ename,comm
fromemployees
wherecomm<=400
selectempno,ename,comm
fromemployees
wherecomm<=400
orcommisnull
selectename,job,msal,comm
fromemployees
wherecommisnotnull