Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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.
Posted

SQL
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
 
Share this answer
 
Comments
Srivikas 9-Nov-12 1:02am    
Thank you very much.. :)
Try:

SQL
select sum(Amount) from table1, table2 where table.AccountID = table2.AccountID and
table2.PersonID =1 and table1.Date  = "2012-11-07"
 
Share this answer
 
Comments
Srivikas 9-Nov-12 1:01am    
Thank you very much.. :)
Shanalal Kasim 9-Nov-12 1:07am    
welcome
In untested SQL I give you:

SQL
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.
 
Share this answer
 
Comments
Srivikas 9-Nov-12 1:02am    
Thank you very much.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900