add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE Part
(Part varchar(20),cost numeric(20,6),date_received date);

INSERT INTO Part

VALUES
('846060',28.373,'1/5/2022'),
('846060',27.588,'3/8/2022'),
('846060',29.143,'4/25/2022'),
('846060',29.143,'2/28/2022'),
('70/1300/100',176.500,'1/7/2022'),
('70/1300/100',195.000,'3/19/2022'),
('70/1300/100',77.846,'2/1/2022'),
('80/800/75',76.688,'4/19/2022'),
('80/800/75',76.602,'4/13/2022'),
('800372',0.9925,'1/1/2022'),
('800372',0.9925,'1/19/2022'),
('800372',0.9925,'4/1/2022'),
('800372',0.9925,'3/10/2022');
13 rows affected
select
g.part,
min_cost,
(select max(p1.date_received) from part p1
where p1.part = g.part and p1.cost = g.min_cost) min_cost_date,
max_cost,
(select max(p2.date_received) from part p2
where p2.part = g.part and p2.cost = g.max_cost) max_cost_date
from (select part, min(cost) min_cost, max(cost) max_cost
from part group by part) g
part min_cost min_cost_date max_cost max_cost_date
70/1300/100 77.846000 2022-02-01 195.000000 2022-03-19
80/800/75 76.602000 2022-04-13 76.688000 2022-04-19
800372 0.992500 2022-04-01 0.992500 2022-04-01
846060 27.588000 2022-03-08 29.143000 2022-04-25