关于ASP SQL语句的问题
SQL code
select a.saleuserid as userid,sum(a.totalpoint) as totalpoints from orders a,userinfo b,CommerceAddress c where a.saleuserid=b.userid and b.uclass=1 and a.oclass=6 and a.saleuserid=c.CommerceUserID and sum(a.totalpoint)>1000000 and orderdate<='2012-05-01 23:59:59' group by a.saleuserid order by totalpoints desc
我想让totalpoints 大于100000的数据显示出来,如何写,谢谢!
------解决方案--------------------
select a.saleuserid as userid,sum(a.totalpoint) as totalpoints from orders a,userinfo b,CommerceAddress c where a.saleuserid=b.userid and b.uclass=1 and a.oclass=6 and a.saleuserid=c.CommerceUserID and sum(a.totalpoint)>1000000 and orderdate<='2012-05-01 23:59:59'
group by a.saleuserid
having sum(a.totalpoint) > 100000
order by totalpoints desc
------解决方案--------------------sql逻辑查运行的各个运行阶段表明
group by 在 where之后运行
where语句中不能使用聚合计算筛选
如果要对聚合结果进行筛选,应该在having子句中