我有这张桌子: datatable 我想写一个查询,用下面的数字更新整个99,这样每个99将被下面的数字替换,每个空白名称,下面的名称。
我试过了:
update datatable.code set datatable.code= previous (datatable.code)
WHERE datatable.code=99;
答案 0 :(得分:1)
update abc set code =
CASE WHEN name='Jean' THEN 1
WHEN name='Peter' THEN 2
END
where code=99;
答案 1 :(得分:0)
使用没有更新的mysql
select *,
if(ta.code!=99,ta.code, select ta2.code from table_a as ta2 where ta2.ID_q=ta.ID_q and ta.code!=99 limit 1) as code_a,
if(ta.name!='',ta.name, select ta2.name from table_a as ta2 where ta2.ID_q=ta.ID_q and ta.name!='' limit 1) as name_a
from table_a as ta;