MySql中的跨表更新查询

发布于 2024-08-13 14:05:58 字数 465 浏览 4 评论 0原文

我可以在 SQL Server 中执行这种查询:

update tblmembers 
set hits_archived = 
  (select count(*) 
   from tblhits 
   where tblhits.target_id=tblmembers.id 
   and tblhits.hitdate < '2009-11-01') 
where tblmembers.regdate < '2007-09-28'

How can I do this in MySql 4.0.23? 我尝试执行该查询,但它返回此错误消息:

您的 SQL 语法中有错误。检查与您的 MySQL 服务器版本相对应的手册,了解在 'select count(*) from tblhits where tblhits.target_id=tblmem 附近使用的正确语法

I can execute this kind of query in SQL Server:

update tblmembers 
set hits_archived = 
  (select count(*) 
   from tblhits 
   where tblhits.target_id=tblmembers.id 
   and tblhits.hitdate < '2009-11-01') 
where tblmembers.regdate < '2007-09-28'

How can I do this in MySql 4.0.23?
I tried to execute the query, but it returned this error message:

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 'select count(*) from tblhits where tblhits.target_id=tblmem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗫嚅 2024-08-20 14:05:58

这也可以通过使用 MySQL 的子查询来完成。

子查询语法

This can also be done with a subquery using MySQL.

Subquery Syntax

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文