sql查询的时候能直接对结果进行过滤么

z961652881 2015-06-19 03:49: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
比如这个sql,我只想要sum结果大于30的所有用户
...全文
392 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
道玄希言 2015-06-22
  • 打赏
  • 举报
回复
做成视图不就OK了额 视图就是一个查询结果集
rick-he 2015-06-20
  • 打赏
  • 举报
回复
引用 4 楼 z961652881 的回复:
[quote=引用 3 楼 ACMAIN_CHM 的回复:] 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 用法。
请教下有买有办法我返回team_id的列表存起来被其他sql使用,比如我现在有个sql文件,里面需要用到这样统计出来的team_id结果集,但是我现在不知道怎么存这个结果集,所以每次用到的时候哦都会用这个sql查一遍,这样导致我跑这个sql文件变得很慢,我知道set可以存参数给其他sql使用,但是我不知道结果集怎么存[/quote] 可以考虑用存储过程啊
z961652881 2015-06-19
  • 打赏
  • 举报
回复
引用 3 楼 ACMAIN_CHM 的回复:
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 用法。
请教下有买有办法我返回team_id的列表存起来被其他sql使用,比如我现在有个sql文件,里面需要用到这样统计出来的team_id结果集,但是我现在不知道怎么存这个结果集,所以每次用到的时候哦都会用这个sql查一遍,这样导致我跑这个sql文件变得很慢,我知道set可以存参数给其他sql使用,但是我不知道结果集怎么存
ACMAIN_CHM 2015-06-19
  • 打赏
  • 举报
回复
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 用法。
z961652881 2015-06-19
  • 打赏
  • 举报
回复
引用 1 楼 u011575570 的回复:
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; 用子查询
除了字查询就没有别的办法了么
rick-he 2015-06-19
  • 打赏
  • 举报
回复
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; 用子查询

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧