vues
This commit is contained in:
25
banque.functions.md
Normal file
25
banque.functions.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Fonctions
|
||||
|
||||
```sql
|
||||
insert into exchange_rate values
|
||||
('EUR', '1999-01-04', 1),
|
||||
('USD', '1999-01-04', 1.1789),
|
||||
('YEN', '1999-01-04', 133.73);
|
||||
```
|
||||
|
||||
```sql
|
||||
create or replace function latest_exchange_rate (
|
||||
p_code text,
|
||||
p_date date
|
||||
)
|
||||
returns decimal
|
||||
language sql
|
||||
as $$
|
||||
select rate
|
||||
from exchange_rate
|
||||
where currency_code = p_code
|
||||
and date < p_date
|
||||
order by date desc
|
||||
limit 1;
|
||||
$$;
|
||||
```
|
||||
Reference in New Issue
Block a user