Here's a MySQL solution:
UPDATE mytable
SET number = (@n := COALESCE(number, @n))
ORDER BY date;
This is concise, but won't necessary work in other brands of RDBMS. For other brands, there might be a brand-specific solution that is more relevant. That's why it's important to tell us the brand you're using.
It's nice to be vendor-independent, as @Pax commented, but failing that, it's also nice to use your chosen brand of database to its fullest advantage.
Explanation of the above query:
@n
is a MySQL user variable. It starts out NULL, and is assigned a value on each row as the UPDATE runs through rows. Where number
is non-NULL, @n
is assigned the value of number
. Where number
is NULL, the COALESCE()
defaults to the previous value of @n
. In either case, this becomes the new value of the number
column and the UPDATE proceeds to the next row. The @n
variable retains its value from row to row, so subsequent rows get values that come from the prior row(s). The order of the UPDATE is predictable, because of MySQL's special use of ORDER BY with UPDATE (this is not standard SQL).