begin
ss:='select KH from fx group by KH where 1=1';
if BJ_AA.Text<>'' then
begin
s1:='%'+BJ_AA.Text+'%';
ss:=ss+' and xh like '''+s1+'''';
end;
if ND_AA.Text<>'' then
ss:=ss+' and nd='''+ND_AA.Text+'''';
if XQ_AA.Text<>'' then
ss:=ss+' and xq='''+XQ_AA.Text+'''';
query.Close;
query.SQL.Clear;
query.SQL.Add(ss);
query.Open;
好像group by 后面只能接having 但是having 后面又不能接上这么多条语句。请帮帮忙!
谢谢!!

解决方案 »

  1.   

    begin
    ss:='select KH from fx where 1=1';
    if BJ_AA.Text<>'' then
    begin
    s1:='%'+BJ_AA.Text+'%';
    ss:=ss+' and xh like '''+s1+'''';
    end;
    if ND_AA.Text<>'' then
    ss:=ss+' and nd='''+ND_AA.Text+'''';
    if XQ_AA.Text<>'' then
    ss:=ss+' and xq='''+XQ_AA.Text+'''';
    ss := ss + ' group by KH';
    query.Close;
    query.SQL.Clear;
    query.SQL.Add(ss);
    query.Open;
      

  2.   

    group by KH 
    放到where 后面
    看看帮助
      

  3.   

    把WHERE 放到group by 前面
      

  4.   

    是呀,把Where 放到 Group by  前面
    Group by 后面只能用 having 加条件