Exemplu:
select judet,denumire from localitati
în loc de:
select * from localitati
Exemplu:
select disciplina,count(*) nr from rezultate where anuniv=2014 group by disciplina
în loc de:
select disciplina,anuniv,count(*) nr from rezultate group by disciplina,anuniv having anuniv=2014
Exemplu:
select * from rezultate where (anuniv,nota)=(select max(anuniv),max(nota) from rezultate)
în loc de:
select * from rezultate where anuniv=(select max(anuniv) from rezultate) and nota=(select max(nota) from rezultate)
Exemplu:
select * from studenti s where exists (select sectia,nrmatricol from rezultate r where s.sectia=r.sectia and s.nrmatricol=r.nrmatricol and anuniv=2014)
în loc de:
select * from studenti where (sectia,nrmatricol) in (select sectia,nrmatricol from rezultate where anuniv=2014)
Exemplu:
select nume,prenume from studenti s where exists (select disciplina from rezultate r where s.sectia=r.sectia and s.nrmatricol=r.nrmatricol and anuniv=2014)
în loc de:
select distinct nume,prenume from studenti s,rezultate r where s.sectia=r.sectia and s.nrmatricol=r.nrmatricol and anuniv=2014
Exemplu:
select * from studenti where nume like 'Pop%'
în loc de:
select * from studenti where substr(nume,1,3)='Pop'
Exemplu:
select a.cod,denumire from produse a left join structura b on a.cod=b.cod where b.cod is null order by denumire;
în loc de:
select cod,denumire from produse where cod not in (select cod from structura) order by denumire;
Exemplu:
select * from studenti where sectia=43
în loc de:
select * from studenti where sectia='43'
Exemplu:
create global temporary table infrezultate (sectia number, nrmatricol char(10), media number, nrcredite number, nrdisc number); insert into infrezultate select sectia,nrmatricol,to_char(sum(notamax*nrcredite)/sum(nrcredite),'99.99') media,sum(nrcredite) nrcredite,count(*) nrdisc from (select sectia,nrmatricol,max(nota) notamax,nrcredite from rezultate where nota>4 group by sectia,nrmatricol,nrcredite having sum(nrcredite)>0 ) group by sectia,nrmatricol; select * from infrezultate;
Interogarea va fi:
select s.sectia,s.nrmatricol,nume,prenume,cnp,media,nrcredite,nrdisc from studenti s inner join infrezultate r on s.sectia=r.sectia and s.nrmatricol=r.nrmatricol;
în loc de:
select s.sectia,s.nrmatricol,nume,prenume,cnp,media,nrcredite,nrdisc from studenti s inner join (select sectia,nrmatricol,to_char(sum(notamax*nrcredite)/sum(nrcredite),'99.99') media,sum(nrcredite) nrcredite,count(*) nrdisc from (select sectia,nrmatricol,max(nota) notamax,nrcredite from rezultate where nota>4 group by sectia,nrmatricol,nrcredite having sum(nrcredite)>0 ) group by sectia,nrmatricol ) r on s.sectia=r.sectia and s.nrmatricol=r.nrmatricol;