记录集模板SQL连接 [英] Recordset Template SQL Join
问题描述
我必须与查询记录集模板的框架进行交互,才能访问数据库以获取ADO记录.这里没有问题.问题:我需要联接2个表才能查询第二个表字段.现在,我查询第一个记录集以获取最初过滤的记录,然后使用过滤的ID遍历第二个表以查看我的第二个约束是否通过.
I am having to interface with a framework which I query for a recordset templates, to access the database for the ADO records. No issues here. Issue : I need to JOIN 2 tables to query the 2nd tables field. Right now I query the 1st recordset to get my initially filtered records, then loop through the 2nd table with the filtered id''s to see if my 2nd constraint passes. Is this even possible?
推荐答案
我不确定这样的方法是否有帮助?
以下代码查找不同的经理ID,然后将它们与ValidAccounts表中找到的不同的帐户ID结合起来,然后加入accToCompany字段,因为这是FK:
I am unsure if something like this helps?
the following code looks for the distinct manager id''s then marries them up with the distinct account id''s that are found in the ValidAccounts table, then joins the accToCompany field as this is a FK:
SELECT DISTINCT Customer.ManagerId, Company.AccountId, Count(1) as "Dist Count"
FROM ValidAccounts
INNER JOIN accToCompany ON ValidAccounts.Id = acctoCompany.accId
INNER JOIN Customer ON accToCompany.ManagerId = Customer.ManagerId
GROUP BY Customer.ManagerId, acctoCompany.accId ORDER BY Count(1) DESC
这给了我类似的东西:
This gives me something like:
ManagerId | AccId | DistCount
FoxB 4017 57
不知道这是否符合您要查找的内容,但它的用途是查询多个表,在这种情况下要有一个目标,以查找不同的值并匹配经理和帐户ID.
Psymon25
Not sure if this is along the lines of what you are looking for but it what it does is query multiple tables with a goal in mind in this case finding distinct values and matching the manager and account ids.
Psymon25
这篇关于记录集模板SQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!