WITH view_local_1 AS (SELECT ... ) [, view_local_2 AS (SELECT ... )] ... SELECT ...(se pot utiliza: view_local_1, view_local_2, ...)
Exemplu:
with v1 as (select sectia,nrmatricol,max(nota) notamax,nrcredite from rezultate where nota>4 group by sectia,nrmatricol,nrcredite ), v2 as (select sectia,nrmatricol,to_char(sum(notamax*nrcredite)/sum(nrcredite),'99.99') media, sum(nrcredite) nrcredite,count(*) nrdisc from v1 group by sectia,nrmatricol ) select s.sectia,s.nrmatricol,nume,prenume,cnp,media,nrcredite,nrdisc from studenti s inner join v2 on s.sectia=v2.sectia and s.nrmatricol=v2.nrmatricol;
Referinţe: