Vous pouvez utiliser PREMIER/DERNIER fonctions d'agrégation pour simplifier ce type de requête.
Requête :
select
sku,
max(price) keep (dense_rank first order by purchase_date) first_purchase_price,
max(price) keep (dense_rank last order by purchase_date) last_purchase_price
from
store
group by
sku;
| SKU | FIRST_PURCHASE_PRICE | LAST_PURCHASE_PRICE |
|--------|----------------------|---------------------|
| BC123 | 3.09 | 6.68 |
| QERT1 | 9.09 | 13.23 |
| QQQ789 | 4.01 | 4.01 |
| WW000 | 200.01 | 200.01 |
| YZV11 | 230.23 | 6.68 |