您的思路混乱! (1)分组后形成新的查询 select aaa,bbb,ccc,count(*) from c:\tabel.dbf group by aaa,bbb,ccc 这时可对分组进行刷选,如count(*)>2,或sum(OthersField)100 如: select aaa,bbb,ccc,count(*) from c:\tabel.dbf group by aaa,bbb,ccc having count(*)>2 或 select aaa,bbb,ccc,count(*) from c:\tabel.dbf group by aaa,bbb,ccc having sum(OthersField)100 (2)要将满足条件的找出来可用 select * from c:\tabel.dbf where (aaa,bbb,ccc) in ( select aaa,bbb,ccc,count(*) from c:\tabel.dbf group by aaa,bbb,ccc having count(*)>2 )您对sql 语句不太清楚!请多关注我的贴子http://www.csdn.net/expert/topic/348/348476.shtm
TO:Lnq(lnq) 我按你的說法改過了,但還是有錯! 為什么? begin d1:='select * from "c:\hrpb\l_zunpsh.dbf"'+ ' where (zunpsh,lib,zunyc,h_s) in ('+ ' select zunpsh,lib,zunyc,h_s,count(*) from "c:\hrpb\l_zunpsh.dbf"'+ ' group by zunpsh,lib,zunyc,h_s'+ ' order by zunpsh desc, lib desc, zunyc asc, h_s desc'+ ' having count(*)>2)'; with query1 do begin close; sql.clear; sql.add(d1); execsql; open; END; end;錯誤提示: Invalid use of keyword. Token: ,lib,zunyc,h_s) Line Number:1
(1)分组后形成新的查询
select aaa,bbb,ccc,count(*) from c:\tabel.dbf
group by aaa,bbb,ccc
这时可对分组进行刷选,如count(*)>2,或sum(OthersField)100 如: select aaa,bbb,ccc,count(*) from c:\tabel.dbf
group by aaa,bbb,ccc
having count(*)>2
或
select aaa,bbb,ccc,count(*) from c:\tabel.dbf
group by aaa,bbb,ccc
having sum(OthersField)100
(2)要将满足条件的找出来可用
select * from c:\tabel.dbf
where (aaa,bbb,ccc) in (
select aaa,bbb,ccc,count(*) from c:\tabel.dbf
group by aaa,bbb,ccc
having count(*)>2
)您对sql 语句不太清楚!请多关注我的贴子http://www.csdn.net/expert/topic/348/348476.shtm
我按你的說法改過了,但還是有錯! 為什么?
begin
d1:='select * from "c:\hrpb\l_zunpsh.dbf"'+
' where (zunpsh,lib,zunyc,h_s) in ('+
' select zunpsh,lib,zunyc,h_s,count(*) from "c:\hrpb\l_zunpsh.dbf"'+
' group by zunpsh,lib,zunyc,h_s'+
' order by zunpsh desc, lib desc, zunyc asc, h_s desc'+
' having count(*)>2)'; with query1 do
begin
close;
sql.clear;
sql.add(d1);
execsql;
open;
END;
end;錯誤提示:
Invalid use of keyword.
Token: ,lib,zunyc,h_s)
Line Number:1