一句mysql的sql语句,执行出现错误,原因求助。
两张表。统计数据后,结构更新到wz_blog表中。sql:updatewz_blogsetwz_blog.comnum=wz_comment.cnumFrom(selec...
两张表。统计数据后,结构更新到wz_blog表中。
sql:
update wz_blog
set wz_blog.comnum = wz_comment.cnum
From (select gid,count(*) AS cnum from wz_comment group by gid) wz_comment
where wz_blog.gid =wz_comment.gid
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From (select gid,count(*) AS cnum from kanwz_comment group by gid) kanwz_comment' at line 3 展开
sql:
update wz_blog
set wz_blog.comnum = wz_comment.cnum
From (select gid,count(*) AS cnum from wz_comment group by gid) wz_comment
where wz_blog.gid =wz_comment.gid
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From (select gid,count(*) AS cnum from kanwz_comment group by gid) kanwz_comment' at line 3 展开
4个回答
2013-03-05
展开全部
update 语句后面不可以跟 from 的,你上面的SQL可以这样写
update wz_blog
set wz_blog.comnum =
(select count(*) from wz_comment where wz_comment.gid = wz_blog.gif)
where exists (select 1 from wz_comment where wz_comment.gid = wz_blog.gif)
update wz_blog
set wz_blog.comnum =
(select count(*) from wz_comment where wz_comment.gid = wz_blog.gif)
where exists (select 1 from wz_comment where wz_comment.gid = wz_blog.gif)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
UPDATE wz_blog, (select gid,count(*) AS cnum from wz_comment group by gid) wz_comment SET wz_blog.comnum=wz_comment.cnum WHERE wz_blog.gid =wz_comment.gid;
你试试看,如果不行再跟我讲
你试试看,如果不行再跟我讲
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
update wz_blog
set comnum=(select count(*) as cnum from wz_comment where wz_blog.gid =wz_comment.gid group by gid)
set comnum=(select count(*) as cnum from wz_comment where wz_blog.gid =wz_comment.gid group by gid)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-05
展开全部
update
wz_blog
set
wz_blog.comnum = (select count(*) AS cnum from wz_comment where wz_blog.gid = wz_comment.gid);
wz_blog
set
wz_blog.comnum = (select count(*) AS cnum from wz_comment where wz_blog.gid = wz_comment.gid);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询