SELECT SUM(amount)as a,team_id FROM t_order where `status` = 1 and type = 0 and create_time >= '2015-06-24 00:00:00' and create_time<'2015-06-25 00:00:00' GROUP BY team_id
比如这个sql,我只想要sum结果大于30的所有用户
...全文
3926打赏收藏
sql查询的时候能直接对结果进行过滤么
SELECT SUM(amount)as a,team_id FROM t_order where `status` = 1 and type = 0 and create_time >= '2015-06-24 00:00:00' and create_time<'2015-06-25 00:00:00' GROUP BY team_id 比如这个sql,我只想要sum结果大于30的所有用户
SELECT SUM(amount)as a,team_id FROM t_order where `status` = 1 and type = 0 and create_time >= '2015-06-24 00:00:00' and create_time<'2015-06-25 00:00:00' GROUP BY team_id
having SUM(amount)>30
网上搜索一下SQL 语法中的 Having 用法。
select * from (SELECT SUM(amount)as a,team_id FROM t_order where `status` = 1 and type = 0 and create_time >= '2015-06-24 00:00:00' and create_time<'2015-06-25 00:00:00' GROUP BY team_id) tableA where a>30;
用子查询