表中的和值以及其他表的引用 [英] Sum value from table with reference from other table

查看:68
本文介绍了表中的和值以及其他表的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有2张桌子。 tblCurrTrx和tblTransaction。

tblCurrTrx存储交易数据。 tblTransaction存储交易ID,描述。



在tblCurrTrx上也有列TransID。如何编写sql语句来选择tblCurrTrx.dblAmount中的总量,其中tblCurrTrx.TransID = tblTransaction.TransID?



在tblTransaction上,我只有2个值,那个是S01和S02。所以在tblCurrTrx中,有10个事务有4个S01和6个S02。我想运行一个查询来选择S01的总和。第二个查询将获得S02的总和。谁能解释一下?我在这里做了一些询问。但它失败了。



Hi all,

I have 2 table. tblCurrTrx and tblTransaction.
tblCurrTrx store the transaction data. tblTransaction store the Transaction ID, Description.

On tblCurrTrx also have column TransID. How to write sql statement to select the total amount in tblCurrTrx.dblAmount where the tblCurrTrx.TransID = tblTransaction.TransID?

On tblTransaction, I have 2 value only, that''s is S01 and S02. So in tblCurrTrx, there is 10 transaction that have 4 S01 and 6 S02. And I want to run a query to select the sum amount of S01. Second query will get the sum of S02. Can anyone explain? I have made some query here. But it''s failed.

strSQl="SELECT tblCurrTrx, SUM (tblCurrTrx.dblAmount) WHERE " & _
tblCurrTrx.TransID=tblTransaction.TransID AND " & _
tblCurrTrx.CollectionNo='" & strCollectNo & "' GROUP BY tblTransaction.TransID"





我的朋友说我应该使用INNER JOIN,但我不知道如何写它。请帮助



My pal said I should use INNER JOIN but I have no idea how to write it. Please help

推荐答案

这应该让你入门.. http://msdn.microsoft.com/en-us/library/office/bb243855(v = office.12).aspx [ ^ ]



我建议先在SQL中试用它,直到你让它工作,然后将其转换为你的代码(strSql = ... etc) - 你会获得更有意义的错误消息,可以帮助您发现您做错了什么。例如,您在上面的示例中没有FROM子句
This should get you started ..http://msdn.microsoft.com/en-us/library/office/bb243855(v=office.12).aspx[^]

I would suggest trying it out in SQL first until you get it to work, and then convert it into your code ("strSql = ...etc") - you''ll get more meaningful error messages that should help you spot what you''re doing wrong. For example you don''t have FROM clause in the example above


这篇关于表中的和值以及其他表的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆