需要一个典型的查询 [英] A typical query needed
问题描述
大家好,
我有一张桌子,
帐号ID |日期|金额|
-----------------------------------
1 | 2012-11-07 | 5000 |
2 | 2012-11-07 | 6000 |
3 | 2012-11-07 | 1000 |
4 | 2012-11-14 | 5000 |
另一个映射表为
帐号ID | PersonID |
-----------------------
1 | 1 |
2 | 1 |
3 | 2 |
4 | 1 |
现在我要获取属于"PersonID" = 1的金额"总数,日期应为"2012-11-07" ...
请尽快回复...
在此先感谢
问候,
Srivikas.
Hi everybody,
I have a tables as
AccountID | Date | Amount |
-----------------------------------
1 | 2012-11-07 | 5000 |
2 | 2012-11-07 | 6000 |
3 | 2012-11-07 | 1000 |
4 | 2012-11-14 | 5000 |
and another mapping table as
AccountID | PersonID |
-----------------------
1 | 1 |
2 | 1 |
3 | 2 |
4 | 1 |
Now I want to get the total of "Amount" which belongs to "PersonID" = 1 and the date should be "2012-11-07"...
Please reply ASAP...
Thanks in advance
With regards,
Srivikas.
推荐答案
select sum(Amount),table2.personid from table1
Join table2 ON table.AccountID = table2.AccountID
where table2.PersonID =1
and table1.Date = "2012-11-07"
group by table2.personid
尝试:
Try:
select sum(Amount) from table1, table2 where table.AccountID = table2.AccountID and
table2.PersonID =1 and table1.Date = "2012-11-07"
在未经测试的SQL中,我给你:
In untested SQL I give you:
Select Sum(Amount) as Amount from Account inner join PersonAccount on Amount.AccountID=PersonAccount.AccountID where PersonAccount.AccountID=1 and Account.Date='2012-11-07'
这假定问题中未提供的表名.
我希望它能起作用.
This assumes the names of the tables which weren''t supplied in the question.
I hope it works.
这篇关于需要一个典型的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!