gpt4 book ai didi

MySQL - 多行总数的百分比

转载 作者:行者123 更新时间:2023-11-29 07:05:25 25 4
gpt4 key购买 nike

我得到了 Table具有多个市场详细信息,我想在新列中获取总销售额的百分比,例如 this 。我尝试了以下代码,但它不起作用。

Select Market, Sale, Sale*100/t.s as %total
from mytablename
cross join (select sum(Sale) as s from mytablename
group by Market

有人可以帮忙吗?

谢谢

最佳答案

使用子查询和聚合函数:

Select t.Market, sum(t.Sale), sum(Sale)*100.0/total.s as `%total`
from mytablename t cross join
(select sum(Sale) as s from mytablename) total
group by t.Market;

关于MySQL - 多行总数的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41906248/

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