1.where 语句在group by 的前面。

2.order by 语句在最后。

3group by 后跟having 语句。

4.拼接sql语句时如下,字符串变量strSQLCondition直接添加,不要用'''   ''' 括起来。

    str_sql := 'select  * from(select pzh, xm, fb, je=sum(je), czbh,czxm from DBF_CFYP '
    + strSQLCondition
       +' group by pzh, xm, fb, czbh, czxm'
    +')a left join'
     + '(select pzh, 个人账户= sum(jrgrzhje), 统筹账户=sum(jrtczhje),刷卡金额=sum(skje), 自费金额=sum(zfje) from sf_ybcFYS  group by pzh'
     //+
     +')b '
     + ' on a.pzh = b.pzh';