我现在的做法是
for i:=1 to  7 do
  for j:=1 to 28 do
     if j<=9 then 
jdate='0'+inttostr(j);
     to_char(thedate,'yyyymmdd')='200602'+
    
     执行(sqlstr);
  next  next

解决方案 »

  1.   

    眼熟,要想提高统计效率,不一定非得一个sql出统计结果,可以尝试select * from a ,在代码中加工你的ResultSet,可以放在ArrayList中,判断,累加,处理起来快。
      

  2.   

    我现在的做法是(代码部分是delphi,应该可以明白的)
    for i:=1 to  7 do
      for j:=1 to 28 do
         sqlstr:='select ';
         if j<=9 then 
           jdate='0'+inttostr(j)
         else 
           jdate=inttostr(j);
         cond2=to_char(thedate,'yyyymmdd')='200602'+jdate
         if i=1 then cond1:='(select count(1) from a where '+cond2+' and bj1=1) bj1,';
         if i=2 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj2=1) bj2,';
         if i=3 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj3=1) bj3,';
         if i=4 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj4=1) bj4,';
         if i=5 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj5=1) bj5,';
         if i=6 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj6=1) bj6,';
         if i=7 then cond1:=cond1+'(select count(1) from a where '+cond2+'bj7=1) bj7,';
         if cond1='' then cond1:='(select count(1) from a where '+cond2+'bj1=1) bj1,';
         sqlstr:=sqlstr+copy(cond1,1,length(cond1)-1)+' from dual';
         执行(sqlstr);
      next
    但效率很不高,请指点!!
      

  3.   

    使用sum(decode 或者sum(case..楼上的方法很容易死人的..
      

  4.   

    谢谢jametong(jametong)
    改用sum(case方法确实提速不少!但整体还是较慢呀!
      

  5.   

    是不是表本来就很大..如果有where条件, 是不是使用了合适的索引..
      

  6.   

    谢谢jametong(jametong)是还有where条件的
    现在已找到更好的方法!比原来速度提高十几倍!结贴!