banque
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
# Les vues
|
||||
|
||||
Une vue SQL est un objet de la base de données qui représente le résultat d’une requête SQL enregistrée.
|
||||
Elle se comporte comme une table virtuelle : on peut la consulter avec SELECT comme une table, mais elle ne stocke pas de données.
|
||||
|
||||
La définition de la vue est enregistrée dans la base, et chaque fois qu’on interroge la vue, la base réexécute la requête sous-jacente.
|
||||
|
||||
```sql
|
||||
create or replace view holder_detail as
|
||||
select h.id, h.type,
|
||||
case
|
||||
when type = 'PERSON' then firstname || ' ' || lastname
|
||||
else name
|
||||
when type = 'PERSON' then firstname || ' ' || lastname
|
||||
when type = 'COMPANY' then c.name
|
||||
when type = 'BANK' then b.name
|
||||
end as nom,
|
||||
case
|
||||
when type = 'PERSON' then age(birthdate)
|
||||
when type = 'COMPANY' then age(c.created_at)
|
||||
when type = 'PERSON' then age(birthdate)
|
||||
when type = 'COMPANY' then age(c.created_at)
|
||||
end as age
|
||||
from holder h
|
||||
left join person p on p.id = h.id
|
||||
left join company c on c.id = h.id;
|
||||
left join bank b on b.id = h.id;
|
||||
```
|
||||
|
||||
```sql
|
||||
|
||||
Reference in New Issue
Block a user