0

我在访问表中有两个表:一个包含当事人名称、地址、期初余额,表二包含当事人名称、净额、贷方金额、借方金额、最终金额。

table 1                           | table 2                           
partyname  address openingbalance | partyname  netamount  creditamount debitamount finalamo

Pinakin    aaa       5000         | Pinakin     10000     100          1000        9100
Mitesh     bbb       7000         | Pinakin     5000      500             0        5500
                                  | Pinakin     15000     5000         500         19500
                                  | Mitesh      10000     2000            0        12000
                                  | Mitesh      3000      0            500         2500

我想要给我这样的结果的查询(我想使用 c# 在 winforms 中制作报告):

Partyname address Openingbalance netamount creditamount debitamount finalamount

Pinakin   aaa      5000          30000     5600          1500       39100
Mitesh    bbb      7000          13000     2000           500       21500

total              12000         43000     7600          2000       60600
4

1 回答 1

0

尝试这个:

SELECT table1.partyname, 
       max(table1.address), 
       sum(table2.netamount), 
       sum(table2.creditamount), 
       sum(table2.debitamount)
  FROM table1 INNER JOIN table2 ON table1.partyname = table2.partyname
 GROUP BY table1.partyname
于 2012-07-29T18:26:29.547 回答