mysql - 分组总和摘要
问题描述
我有如下的sql:
select
count(*), sum(summary.imp), sum(summary.taps)
from(
select
sum(impressions) as imp, sum(taps) as taps
from report
where org_id = 1 and report_date between '2019-01-01' and '2019-10-10'
group by org_id, country, text)
summary;
此查询在 MYSQL 中创建派生临时表。有没有办法用其他方法解决它?
解决方案
我已经阅读(但尚未测试)MySQL 支持不同计数的多个列:
select
count(distinct org_id, country, text), sum(impressions) as imp, sum(taps) as taps
from report
where org_id = 1 and report_date between '2019-01-01' and '2019-10-10'
我很想知道这是不是真的。我也有理由相信这样的事情会奏效:
select
count(distinct concat_ws('###', org_id, country, text)), sum(impressions) as imp, sum(taps) as taps
from report
where org_id = 1 and report_date between '2019-01-01' and '2019-10-10'
推荐阅读
- android - 我的应用无法在 Android 7.0 及更早版本上运行
- php - 使用另一个 php 文件中的变量并在查询 isset 后恢复它
- django - 为什么当我将“LoginRequiredMixin”传递给 Django 中的“视图”时,我无法将表单提交到数据库?
- python - 使用 spotipy 的 util.prompt 进行回溯
- flutter - 如何获取 Firestore 上另一个集合内的集合内的所有文档?
- html - CSS 背景 SVG 不显示
- java - 如何解决“论点不同!Junit 和 Mockito 中的通缉犯错误
- java - 如何保存在 JPanel 中绘制的线条?
- windows - 直到 WaitForSingleObject 返回的时间
- vue.js - vuetable - 没有可用的数据