三表关联,多字段连续分组,这些应该都是严重影响查询的原因之一,但在查询分析器和TADOQUERY里面速度相差太大,一个不到1S,一个》10S,我的数据不多,不到100条。
在SQL SERVER 的查询分析器里运行:
select hotelmang.mangname,count(hotelmang.mangname) as mangsum,vipcustomer.vipname,
count(vipcustomer.vipname) as vipsum,vipcustomer.vipcompany,
count(vipcustomer.vipcompany) as cpsum,contactfct,count(contactfct) as fctsum
from vipcontactinfo,hotelmang,vipcustomer
where hotelmang.id=vipcontactinfo.mangid and vipcustomer.id=vipcontactinfo.vipid group by hotelmang.mangname ,vipcustomer.vipname,vipcustomer.vipcompany,contactfct
速度很快
但在DELPHI里面运行:
with ADOTJ do
begin
close;
CacheSize:=1000;
CursorLocation:=clUseClient;
CursorType:=ctStatic;
LockType:=ltBatchOptimistic;
sql.Clear;
sql.text:='select hotelmang.mangname,count(hotelmang.mangname) as mangsum,' +
'vipcustomer.vipname,count(vipcustomer.vipname) as vipsum,' +
'vipcustomer.vipcompany,count(vipcustomer.vipcompany) as cpsum,contactfct,' +
'count(contactfct) as fctsum from vipcontactinfo,hotelmang,vipcustomer ' +
'where hotelmang.id=vipcontactinfo.mangid and vipcustomer.id=' +
'vipcontactinfo.vipid group by hotelmang.mangname,vipcustomer.vipname,vipcustomer.vipcompany,contactfct';
Open;
end;
却很慢,请大家讨论讨论,分不够另开贴再加分!