ADO SQL 使用 group by 查询的结果更新表
我正在尝试使用包含相同值的记录数来更新 .mdb 表中的记录。
下面的 SQL 不起作用,但我认为它表明了我想要实现的目标。
UPDATE table1 AS A
INNER JOIN (SELECT PH_BSP , Count(PH_BSP) AS PHCOUNT FROM table1 GROUP BY PH_BSP) AS B
ON A.PH_BSP=B.PH_BSP
SET A.PH_SORT = B.PHCOUNT;
有什么想法吗?
I am trying to update records in an .mdb table with the number of records containing the same value.
The SQL below does not work but I think gives an indication of what I am trying to achieve.
UPDATE table1 AS A
INNER JOIN (SELECT PH_BSP , Count(PH_BSP) AS PHCOUNT FROM table1 GROUP BY PH_BSP) AS B
ON A.PH_BSP=B.PH_BSP
SET A.PH_SORT = B.PHCOUNT;
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果在 Access 中执行此操作,则需要使用域聚合函数:
上面假设 PH_BSP 是文本字段,如果是数字,则删除单引号。
If you are doing this in Access, you need to use a domain aggregate function:
The above assumes that PH_BSP is a text field, drop the single quotes if it is numeric.
未经测试,但因此列出声明这应该可以解决您的问题
编辑:
您的问题可能来自您的子查询,我会尝试将该部分放入单独的访问查询中,看看它是如何进行的。根据记忆,我曾经在 Access 和子查询方面遇到很多麻烦,方括号有时也会有所帮助,但从记忆来看不太可靠。
Untested, but setting out the statement thusly this should solve your issue
Edit:
Your problem might be from your sub query, I would try putting that part into a separate Access Query and see how it goes. From memory I used to have a lot of trouble with Access and subqueries, square brackets would also sometimes help, but unreliable from memory.
你尝试过类似的事情吗?
我假设这里是 SQL Server。
但我想这个或类似的东西应该可以做到。
Have you tried something alike?
I'm assuming SQL Server here.
But this or something alike should do it, I guess.