mysql 2组使用groupby rollup求和
我有一个查询
select user_id,sum(hours),date, task_id from table whereused_id = 'x' and date >='' and date<= '' group by user_id, date, task_id with roll up< /code>
查询工作正常。但我还需要找到第二个总和(小时),其中按顺序分组发生了变化。
select user_id,sum(hours),date,task_id from table whereused_id = 'x' group by user_id,task_id
(实际的where条件要长得多。)
是否有可能同时获得总和单个查询自where条件几乎相同?
I have a query
select user_id,sum(hours),date, task_id from table where used_id = 'x' and date >='' and date<= '' group by user_id, date, task_id with roll up
The query works fine. But I also need to find a second sum(hours) where the group by order is changed.
select user_id,sum(hours),date, task_id from table where used_id = 'x' group by user_id,task_id
(The actual where condition is much longer.)
Is it possible to get both the sum in a single query since the where condition almost the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的需求,您应该只需要一个或两个
带有汇总的
。Depending on your needs, you should only need one
with rollup
, or two.