求个sql,在mysql下运行 表1id count_21 02 0表2id id11 12 13 24 25 2求个更新语句使得表1变成1 22 3也就是说表2 的id1关联表1的id表1中的count_2 就是 表2中的count后的值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 update tb1,(select id1,count(*) as numfrom tb2group id1)tb3set tb1.count_2=tb3.num where tb1.id = tb3.id 如果我希望 在tb2中没有的 tb1的count_2,能被更新成0 怎么办?这个sql只能跟新掉两表有关联的。 (select id1,count(*) as numfrom tb2group id1)tb3这一段是什么意思?还有我试验了一下,报错Error Code: 1054. Unknown column 'tb3.id' in 'where clause' update tb1 LEFT JOIN (select id1,count(*) as numfrom tb2group id1)tb3 ON tb1.id = tb3.id1set tb1.count_2=IFNULL(tb3.num,0) 从字符串转换为 datetime 时发生语法错误 mysql如何生成随机码? 一个存储过程的优化问题,请大家帮帮忙。 主键设为自增量,如何写入数据库? 如何导入这个文本文件到数据库里? Postgresql的低级问题?脸红!! mysql不能建立数据库 更新表本身,当更新的字段作为where条件时出错,怎么解决? [Important] vs2005 mysql++无法连接mysql数据库 mysql数据库利用主从同步部署为环形互相热备的方案 mysql自定义函数执行出错 mysql set类型怎么修改指定值
from tb2
group id1
)tb3
set tb1.count_2=tb3.num
where tb1.id = tb3.id
如果我希望 在tb2中没有的 tb1的count_2,能被更新成0 怎么办?这个sql只能跟新掉两表有关联的。
from tb2
group id1
)tb3这一段是什么意思?还有我试验了一下,报错
Error Code: 1054. Unknown column 'tb3.id' in 'where clause'
from tb2
group id1
)tb3 ON tb1.id = tb3.id1
set tb1.count_2=IFNULL(tb3.num,0)