One method to do this sans analytic functions uses a correlated subquery:
SELECT
fruit,
amount,
COALESCE(date, (SELECT MIN(date) FROM yourTable t2 WHERE t2.fruit = t1.fruit)) date
FROM yourTable t1;
We could also use an aggregation join approach:
SELECT
t1.fruit,
t1.amount,
COALESCE(t1.date, t2.min_date) AS date
FROM yourTable t1
INNER JOIN
(
SELECT fruit, MIN(date) AS min_date
FROM yourTable
GROUP BY fruit
) t2
ON t2.fruit = t1.fruit;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…