MySQL Query:select u.realname,u.dpcode,u.username,sum(aa.pv),sum(aa.price) as price_or from dg_users as u inner join dg_orders as aa on (u.username=aa.dianpu_flag ) and u.rank>=3 and aa.zftime>=1315195740 and aa.shtime<=1316142599 and aa.state>=3 and sum(aa.price)>=50.00 group by aa.dianpu_flag order by 5 desc 
MySQL Error:Invalid use of group function 
MySQL Errno:1111 
Message:MySQL Query Error  sum(aa.price)>=50.00   这个写错、 不知道该怎么写?

解决方案 »

  1.   

    select ...,sum(aa.price) as aap ... from ... group by by aa.dianpu_flag having aap >= 50.00
      

  2.   

    正确的应该是:select u.realname,u.dpcode,u.username,sum(aa.pv),sum(aa.price) as price_or from {$db_prefix}users as u inner join {$db_prefix}orders as aa on (u.username=aa.dianpu_flag ) and u.rank>=3 and aa.zftime>=".$rs1['kstime']." and aa.shtime<=".$rs1['jstime']." and aa.state>=3 group by aa.dianpu_flag having sum(aa.price)>=".$rs1['e']." order by 5 desc谢谢你。
      

  3.   

    sum(aa.price)>=50.00 改为  price_or>=50.00
      

  4.   

    用了聚合函数就用having做为where的替代.记得这个就行了