我的表格如下:
acc_name dr_amt cr_amt
Cash in hand 10000 0
Share Capital 00 1000
Cash in hand 2000 0
Share Capital 0 2000.00
Vehicles 5000 0
Cash in hand 0 5000
询问如下:
SELECT a.acc_name, sum(j.dr_amt) AS dr_sum, sum(j.cr_amt) AS cr_sum
FROM journal_voucher_details_mcg AS j
INNER JOIN acc_head_mcg AS a ON a.acc_code = j.acc_code
INNER JOIN journal_voucher_mcg AS jv ON jv.jv_no = j.jv_no
WHERE jv.jv_date = 2011-04-08
GROUP BY a.acc_name
我能够取得以下成果:
acc_name dr_sum cr_sum
Cash in hand 3000 5000
Share Capital 0 3000
Vehicles 5000 0
但我想有两条手头现金条目(以及任何双干_和 cr子都超过0的条目),结果如下:
acc_name dr_sum cr_sum
Cash in hand 3000 0
Cash in hand 0 5000
Share Capital 0 3000
Vehicles 5000 0
I also need the sum of both dr_sum and cr_sum which in this case should be 8000 to both....My final query is
SELECT *, SUM(dr_sum), SUM(cr_sum)
FROM (SELECT a.acc_name, sum(j.dr_amt) AS dr_sum, sum(j.cr_amt) AS cr_sum
FROM journal_voucher_details_mcg AS j
INNER JOIN acc_head_mcg AS a ON a.acc_code = j.acc_code
INNER JOIN journal_voucher_mcg AS jv ON jv.jv_no = j.jv_no
WHERE jv.jv_date = 2011-04-08
GROUP BY j.acc_code)
但是,这不奏效,真的会赞赏你的努力!
<><>Edit>/strong>
最后成果:
acc_name dr_sum cr_sum
Cash in hand 3000 0
Cash in hand 0 5000
Share Capital 0 3000
Vehicles 5000 0
Total 8000 8000
我无法在最后一个学期展示“Total”(“总数”一词)。