select code,patientsname,patientdepartmentname,amount,day from(
select code,patientsname,patientdepartmentname,amount ,day from tb_hos_outpatientcharges where feetype=1 union all
select recordcode as code,patientname as patientsname,recorddeptname as patientdepartmentname,money as amount,recordtime as day from tb_hos_in_hosfee where feetype=1
)
这个是查询两张表中记账的数据.现在要将同村镇的欠账钱数相加.插入统计表中..而且欠账钱数每天都会增加新的,怎么累加到统计表中?..求高手指教.

解决方案 »

  1.   

        CODE PATIENTSNAME PATIENTDEPARTMENTNAME AMOUNT DAY 
    1 123 陈彬 丁桥 100 2011-06-13 
    2 141 陈彬 蓉城镇 10 2011-06-13 
    3 201 陈彬 杜村 5 2011-06-03 
    4 301 方世玉 城东乡 80 2011-06-14 
    5 302 李斯 丁桥 80 2011-06-14 
    6 81 张三 杜村 231 2011-06-02 
    7 41 张三   33 2011-05-26  
    8 102 李四 酉华 500 2011-06-13 
    9 82 张三 丁桥 36 2011-06-02 
    10 40 张三 王圩村 33 2011-05-26  
    11 101 李四 酉华 300 2011-06-13