vues
This commit is contained in:
27
banque.vues.md
Normal file
27
banque.vues.md
Normal file
@@ -0,0 +1,27 @@
|
||||
```sql
|
||||
create or replace view holder_detail as
|
||||
select h.id, h.type,
|
||||
case
|
||||
when type = 'PERSON' then firstname || ' ' || lastname
|
||||
else name
|
||||
end as nom,
|
||||
case
|
||||
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;
|
||||
```
|
||||
|
||||
```sql
|
||||
create or replace view account_detail as
|
||||
select a.balance,
|
||||
a.balance * ah.share as balance_currency,
|
||||
a.balance * ah.share / latest_exchange_rate(a.currency_code, current_date),
|
||||
a.currency_code,
|
||||
hd.nom
|
||||
from account a
|
||||
join account_holder ah on ah.account_id = a.id
|
||||
join holder_detail hd on ah.holder_id = hd.id;
|
||||
```
|
||||
Reference in New Issue
Block a user