mysql 一个表中的两个字段a和b,如何将b的字段值一次性复制给a

pre_common_member_count表中有唯一键uid
及字段a和字段b,a的值为0 b的值不固定,uid是id号.唯一
如何把每一个uid下的b值赋给相应的a字段.
uid a b
------------------------
1 0 80
------------------------
2 0 23
------------------------
3 0 56
能帮写个sql语句吗. 比如
update pre_common_member_count set
最新回答
酒爷

2024-10-31 11:20:23

update pre_common_member_count set a=(select b from pre_common_member_count as pre where uid=pre.uid )
追问
#1093 - You can't specify target table 'pre_common_member_count' for update in FROM clause
追答
update pre_common_member_count  set a=b 就可以了 想复杂了
追问
UPDATE pre_common_member_count A SET my_a=(SELECT my_b FROM ( SELECT my_a,uid FROM pre_common_member_count) B WHERE B.uid=A.uid )

你第二个方法.没试.应该可以.但我这个语句也可以哟.因为mysql不能操作同一个表. 所以.变通了下
泼得千树泪

2024-10-31 08:18:17

update pre_common_member_count set a = (select b from pre_common_member_count pcmc
where uid = pcmc.uid)
青烟离歌

2024-10-31 09:37:50

update table set a values(select b from table where uid=id) where uid=id;应该可以
抱着嫦娥烤玉兔

2024-10-31 11:20:20

Fdfttyfffggyyhyfgrgggfthtgrgfgfgtygggdcedfdfggghhhuuulhuqesddcvb