Company
This commit is contained in:
26
banque.md
26
banque.md
@@ -432,6 +432,14 @@ create table person (
|
|||||||
- Créer une entreprise nommée _Boulangerie de Valorgue_, créée le 19 août 2014, numéro d’immatriculation FR19803269968.
|
- Créer une entreprise nommée _Boulangerie de Valorgue_, créée le 19 août 2014, numéro d’immatriculation FR19803269968.
|
||||||
- Ajouter un nouveau titulaire : _Justin Hébrard_ né le 11/03/1993.
|
- Ajouter un nouveau titulaire : _Justin Hébrard_ né le 11/03/1993.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
create table company (
|
||||||
|
"id" bigint primary key references holder(id),
|
||||||
|
"name" text,
|
||||||
|
"creation_date" date
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
create table bank (
|
create table bank (
|
||||||
"id" bigint primary key references holder(id),
|
"id" bigint primary key references holder(id),
|
||||||
@@ -665,6 +673,24 @@ create table operation (
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Dépôts et retraits
|
||||||
|
|
||||||
|
```sql
|
||||||
|
create or replace procedure add_retrait (
|
||||||
|
p_account_id bigint,
|
||||||
|
p_amount decimal
|
||||||
|
)
|
||||||
|
language plpgsql
|
||||||
|
as $$
|
||||||
|
declare
|
||||||
|
v_id bigint
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Séance 3 : Exploitation des données
|
# Séance 3 : Exploitation des données
|
||||||
|
|
||||||
Ajouter des données
|
Ajouter des données
|
||||||
|
|||||||
@@ -267,12 +267,23 @@ call add_account('EUR', array[1], array[1]);
|
|||||||
call add_account('USD', array[1], array[1]);
|
call add_account('USD', array[1], array[1]);
|
||||||
call add_account('YEN', array[1], array[1]);
|
call add_account('YEN', array[1], array[1]);
|
||||||
|
|
||||||
call add_account('EUR', array[2,3], array[0.6, 0.4]);
|
update account set balance = 100000 where id = 1;
|
||||||
|
update account set balance = 50000 where id = 2;
|
||||||
|
update account set balance = 2000000 where id = 3;
|
||||||
|
|
||||||
|
call add_account('EUR', array[2, 3], array[0.6, 0.4]);
|
||||||
|
|
||||||
call add_person('Kaneda', 'Shōtarō', '1982-12-20');
|
call add_person('Kaneda', 'Shōtarō', '1982-12-20');
|
||||||
call add_account('YEN', array[5], array[1]);
|
call add_account('YEN', array[5], array[1]);
|
||||||
|
|
||||||
create view holder_detail as
|
call add_company('Boucherie Sanzot', 'FR68487684235', '2014-08-14');
|
||||||
|
call add_account('EUR', array[6], array[1]);
|
||||||
|
|
||||||
|
call add_company('America Logistics', '95-4524149', '1996-09-24');
|
||||||
|
call add_account('EUR', array[7], array[1]);
|
||||||
|
call add_account('USD', array[7], array[1]);
|
||||||
|
|
||||||
|
create or replace view holder_detail as
|
||||||
select h.id, h.type,
|
select h.id, h.type,
|
||||||
case
|
case
|
||||||
when type = 'PERSON' then firstname || ' ' || lastname
|
when type = 'PERSON' then firstname || ' ' || lastname
|
||||||
@@ -286,14 +297,20 @@ from holder h
|
|||||||
left join person p on p.id = h.id
|
left join person p on p.id = h.id
|
||||||
left join company c on c.id = h.id;
|
left join company c on c.id = h.id;
|
||||||
|
|
||||||
create view account_detail as
|
create or replace view account_detail as
|
||||||
select a.balance,
|
select a.balance,
|
||||||
a.balance * ah.share as balance_currency,
|
a.balance * ah.share as balance_currency,
|
||||||
|
a.balance * ah.share / latest_exchange_rate(a.currency_code),
|
||||||
a.currency_code,
|
a.currency_code,
|
||||||
hd.nom
|
hd.nom
|
||||||
from account a
|
from account a
|
||||||
join account_holder ah on ah.account_id = a.id
|
join account_holder ah on ah.account_id = a.id
|
||||||
join holder_detail hd on ah.holder_id = hd.id
|
join holder_detail hd on ah.holder_id = hd.id;
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Transactions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
insert into transaction (amount) values (100);
|
insert into transaction (amount) values (100);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user