我在mysql中有一个表,其中包含列描述,数量,所有大小
Description quantity Allsizes
Cap 3 small
0 3 medium
0 3 large
Shirt 2 small
0 2 medium
我想将description列中的'0'替换为它前面的行的值,在这个例子中,o / p将是
Cap 3 small
Cap 3 medium
Cap 3 large
Shirt 2 small
Shirt 2 medium
我如何实现这一目标?非常感谢任何帮助
答案 0 :(得分:0)
尝试以下查询,只需验证您的表格和列名称Demo:
select
e.id,
CASE e.description WHEN '0'
Then
@prev
else
e.description
END as description,
CASE e.description WHEN '0'
THEN
@prev := @prev
ELSE
@prev := e.description
END as current,
e.quantity as quantity,
e.Allsizes
from
(
select
@prev := ''
) as i,
table_name as e
order by
e.id