表如下:名单 质量 数量
小麦 优质 20
大米 一般 20
小麦 优质 50
大米 一般 20
小麦 差 55
DataModule1.AQueryzhanji.Close;
Datamodule1.AQueryzhanji.SQL.Clear;
DataModule1.AQueryzhanji.SQL.Add('select * from 表 order by 日期 DESC'); //查询所有;
DataModule1.AQueryzhanji.Open;DataModule1.AdoQueryGoal.Close;
Datamodule1.AdoQueryGoal.SQL.Clear;
DataModule1.AdoQueryGoal.SQL.Add('select count(*) from 表 where 结果=''优质''');
DataModule1.AdoQueryGoal.Open;
win:=DataModule1.ADOQueryGoal.Fields[0].value; DataModule1.AdoQueryGoal.Close;
Datamodule1.AdoQueryGoal.SQL.Clear;
DataModule1.AdoQueryGoal.SQL.Add('select count(*) from 表 where 结果=''一般''');
DataModule1.AdoQueryGoal.Open;
DataModule1.AdoQuery.Close;
Datamodule1.AdoQuery.SQL.Clear;
DataModule1.AdoQuery.SQL.Add('select count(*) from 表 where 结果='差''');
DataModule1.AdoQuery.Open;分别要计算出优质、差、一般的记录数,用三个QUERY查询,在数据量大时会很慢,甚至出现死机……如何简便?能否有简单的方法?
小麦 优质 20
大米 一般 20
小麦 优质 50
大米 一般 20
小麦 差 55
DataModule1.AQueryzhanji.Close;
Datamodule1.AQueryzhanji.SQL.Clear;
DataModule1.AQueryzhanji.SQL.Add('select * from 表 order by 日期 DESC'); //查询所有;
DataModule1.AQueryzhanji.Open;DataModule1.AdoQueryGoal.Close;
Datamodule1.AdoQueryGoal.SQL.Clear;
DataModule1.AdoQueryGoal.SQL.Add('select count(*) from 表 where 结果=''优质''');
DataModule1.AdoQueryGoal.Open;
win:=DataModule1.ADOQueryGoal.Fields[0].value; DataModule1.AdoQueryGoal.Close;
Datamodule1.AdoQueryGoal.SQL.Clear;
DataModule1.AdoQueryGoal.SQL.Add('select count(*) from 表 where 结果=''一般''');
DataModule1.AdoQueryGoal.Open;
DataModule1.AdoQuery.Close;
Datamodule1.AdoQuery.SQL.Clear;
DataModule1.AdoQuery.SQL.Add('select count(*) from 表 where 结果='差''');
DataModule1.AdoQuery.Open;分别要计算出优质、差、一般的记录数,用三个QUERY查询,在数据量大时会很慢,甚至出现死机……如何简便?能否有简单的方法?
select decode(结果,优质,count(数量),0) into l_good,decode(结果,一般,count(数量),0) into l_gen,decode(结果,差,count(数量),0) into l_bad from 表
select * from 表 order by 日期 DESC这呢,如果库中有个几十万或几百万条数据,你把它全部显示出来肯定要慢得要死,就算你加上索引也不会快到哪儿去,问楼主你的这个表中有多少条数据。
select q4.cnt as allcnt,q1.cnt as q1cnt,q2.cnt as q2cnt,q3.cnt as q3cnt
from
(select count(*) as cnt from qxkz where qxid=0)as q1,
(select count(*) as cnt from qxkz where qxid=1)as q2,
(select count(*) as cnt from qxkz where qxid=2)as q3,
(select count(*) as cnt from qxkz)as q4
然后字段allcnt,q1cnt,q2cnt,q3cnt分别代表总数据行数、好、中、差三种数据行数,
自己相应的改一下就行,
不用多个查询。
DataModule1.AdoQuery1.Close;
Datamodule1.AdoQuery1.SQL.Clear;
DataModule1.AdoQuery1.SQL.Add('select q4.cnt as allcnt,q1.cnt as q1cnt,q2.cnt as q2cnt,q3.cnt as q3cnt
from
(select count(*) as cnt from qxkz where qxid=0)as q1,
(select count(*) as cnt from qxkz where qxid=1)as q2,
(select count(*) as cnt from qxkz where qxid=2)as q3,
(select count(*) as cnt from qxkz)as q4
');DataModule1.AdoQuery1.Open;