gpt4 book ai didi

mysql - 分组总和汇总

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:31 25 4
gpt4 key购买 nike

我有如下的 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'

关于mysql - 分组总和汇总,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58225137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com