gpt4 book ai didi

mysql - MYSQL中如何计算百分比?

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

我不明白,为什么我得到的是 0.01% 而不是 100%,请指教

这是我的查询:

SELECT Total_Price,concat(round(total_price/(SUM(total_price)*100),2),'%') AS percentage
FROM Sales
WHERE Department IN ('SPORT','MUSIC')
AND DATE BETWEEN '2016-01-01' AND '2016-03-30'

谢谢

最佳答案

尝试将总计作为子查询进行...

select t1.total_price, (t1.total_price/t2.grand_total)*100 as pc
from MyTable t1
inner join
(
select sum(tx.total_price) as grand_total
from MyTable tx
AND tx.DATE BETWEEN '2016-01-01' AND '2016-03-30'
) t2
on 1=1
WHERE Department IN ('SPORT','MUSIC')
AND DATE BETWEEN '2016-01-01' AND '2016-03-30'

关于mysql - MYSQL中如何计算百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46426555/

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