回复ATCG(ATCG):
那是一种赋参的形式这样就不必把变量直接写在sql中.如果你用过delphi+oracle,你是怎么样解决按时间分组统计的呢(符合某一时间范围内的数据)

解决方案 »

  1.   

    1、我先不说其它的,首先谈一下你的sql语句。
    adoquery.SQL.Add('select mzno ,sum(total) from ghdj ');
    adoquery.SQL.Add(' where mzno='''+edit1.text+''' group by mzno ');
    这能分组吗?where 后边的条件已指定了mzno是什么,这样一来就不可能分组了,充其量是对指定的mzno统计而已。想分组把where 后边的条件去掉。2、未经测试,自已试一下吧
     adoquery1.sql.add('select rq,count(*) from ghdj where rq >to_date(:rq1,''yyyy-mm-dd'')');
     adoquery1.sql.add(' and rq<to_date(:rq2,''yyyy-mm-dd'')');
     adoquery1.sql.add(' group by rq');参数传值时把时间用datetostr转换传过去就可以了。
      

  2.   

    回复 luoweicaisd(笑三少) :
    if adoquery.Active =true then adoquery.Close ;
    adoquery.SQL.Clear ;
    adoquery.SQL.Add('select ghdate ,sum(total) as totalz from ghdj ');
    adoquery.SQL.Add(' where ghdate<=to_date(:rq1,''yyyy-mm-dd'')  ');
    adoquery.SQL.Add(' group by ghdate ' );
    adoquery.Parameters.ParamByName('rq1').Value :=datetostr(dtp1.Date);
    adoquery.Open ;
    出错提示为"不是group by 表达式"
    当我改成以下形式时运行良好,但没有达到我所要的按时间分组的条件.
    if adoquery.Active =true then adoquery.Close ;
    adoquery.SQL.Clear ;
    adoquery.SQL.Add('select ghdate ,total as totalz from ghdj ');
    adoquery.SQL.Add(' where ghdate<=to_date(:rq1,''yyyy-mm-dd'')  ');
    adoquery.Parameters.ParamByName('rq1').Value :=datetostr(dtp1.Date);
    adoquery.Open ;
    望指点.
      

  3.   

    你的sql语句有问题
    ghdate 返回值是多行的,sum(total)返回值是单行的
    当然有问题
      

  4.   

    你的sql语句有问题
    ghdate 返回值是多行的,sum(total)返回值是单行的
    当然有问题