我现在的做法是
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
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
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
但效率很不高,请指点!!
改用sum(case方法确实提速不少!但整体还是较慢呀!
现在已找到更好的方法!比原来速度提高十几倍!结贴!