如何使用另一个表的计数更新字段 [英] How to update field with count of another tabel
问题描述
你好专家
这是我的问题
我正在使用vb6和ms访问
我有两张桌
表名:客户
id名称数
1 A
2 B
3 C
4 D
count是空白字段
表名:黄金
custid gold
1 1
1 1
2 1
4 1
这里我要更新 <客户表中的b> count 字段计算黄金....结果应该是这样的
表名:客户
id名字数
1 A 2
2 B 1
3 C 0或null
4 D 1
请帮忙解决..
什么我试过了:
谷歌搜索了很多没有找到任何解决方案..... plz help
Hello Experts
This is my issue
I am using vb6 and ms access
I have two table
Table name: Customer
id name count
1 A
2 B
3 C
4 D
count is null field here
Table name: Gold
custid gold
1 1
1 1
2 1
4 1
Here i want to update the count field in customer table with counting of gold.... Result should be like this
Table name: Customer
id name count
1 A 2
2 B 1
3 C 0 or null
4 D 1
Please help to solve..
What I have tried:
Googled a lot not found any solution..... plz help
推荐答案
为什么要更新任何内容?使用简单的加入 [ ^ ]而不是:
Why do you want to update anything? Use simple join[^] instead:
SELECT C.id, c.[name], SUM(g.[gold]) AS [CountOfGold]
FROM Customer AS C INNER JOIN Gold AS G ON C.id = G.custid
GROUP BY C.id, c.[name]
详情请见:
SQL连接的可视化表示 [ ^ ]
SQL聚合函数(SQL) [ ^ ]
这篇关于如何使用另一个表的计数更新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!