1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| CREATE TABLE clients
(clientsId INT, OrderDate DATE, montant MONEY) ;
INSERT clients VALUES
(1, '2016-12-03', '12500')
, (1, '2016-10-07', '15000')
, (1, '2016-09-12', '16000')
, (2, '2016-07-11', '900')
, (2, '2016-09-13', '18000')
, (2, '2016-11-03', '7500')
, (3, '2016-01-29', '19500')
, (3, '2016-04-19', '20000')
, (3, '2016-07-09', '18000') ;
select clientsId,OrderDate,montant,FIRST_VALUE(montant)over (partition by clientsId order by orderDate desc)as first_value,
last_VALUE(montant)over (partition by clientsId order by orderDate asc)as last_value from clients |
Partager