系统:oracle8,delphi 6
使用控件: dbgrid, adoquery
请问各位,通过adoquery从多个表中提取统计数据,如何在adoquery的这个数据集中自动添加一条记录类似"总计"之类的并将所有记录在dbgrid中显示出来?
SQL语句如下:
select chufgj.chi_brf,count(b.visit_type) as "经济贸易", count(c.visit_type) as "科学技术", count(d.visit_type) as "文化体育", count(e.visit_type) as "留学培训", count(f.visit_type) as "劳务输出", count(g.visit_type) as "会议", count(h.visit_type) as "友好访问", count(i.visit_type) as "其他" from chufgj,
(select visit_type,ser_num from tuanz where visit_type='经济贸易') b,
(select visit_type,ser_num from tuanz where visit_type='科学技术') c,
(select visit_type,ser_num from tuanz where visit_type='文化体育') d,
(select visit_type,ser_num from tuanz where visit_type='留学培训') e,
(select visit_type,ser_num from tuanz where visit_type='劳务输出') f,
(select visit_type,ser_num from tuanz where visit_type='会议') g,
(select visit_type,ser_num from tuanz where visit_type='友好访问') h,
(select visit_type,ser_num from tuanz where visit_type='其他') i
where chufgj.ser_num like '182004%P' and chufgj.ser_num=b.ser_num(+)
and chufgj.ser_num=c.ser_num(+)
and chufgj.ser_num=d.ser_num(+)
and chufgj.ser_num=e.ser_num(+)
and chufgj.ser_num=c.ser_num(+)
and chufgj.ser_num=d.ser_num(+)
and chufgj.ser_num=e.ser_num(+)
and chufgj.ser_num=f.ser_num(+)
and chufgj.ser_num=g.ser_num(+)
and chufgj.ser_num=h.ser_num(+)
and chufgj.ser_num=i.ser_num(+)
group by chi_brf

解决方案 »

  1.   

    1使用union 看你会用 (+) 我想union也应该会了
    2.使用enlib控件 就像pb里的datawindow一样方便
      

  2.   

    自动的不行;
    把adoquery 设置成缓存模式,在另一
    adquery中查出sum,然后append adoquery,
      

  3.   

    如何向ADOQUERY查询的数据集中添加记录呢?一添加就出现"没有可供定位的列"之类的问题!
      

  4.   

    这样做没用的,数据太多时要翻好多页才能看见统计数字,客户不会喜欢的。一般都需要固化在底下,要实现比较麻烦,用EHLib或者Express Grid做吧,都是非常强大的网格控件,不过Express Grid很难找到完全汉化版,EHLib就好一些。没必要事事自己写代码,关键是实现客户的需求。
      

  5.   

    1、最方便是用EHLIB中的DBGridEH控件,只要设几下属性就解决了
    2、写SQL语句如
      select a,b,c from yourtable where...
      union
      select '合计',sum(b) as b,sum(c) as c from youtable where```
      

  6.   

    建议用EhLib或者ExpressQuantumGrid均可以方便实现
      

  7.   

    我觉得用SQL语句先求和吧?
    前台显示就可以了啊