gpt4 book ai didi

mysql desc 对我不起作用

转载 作者:行者123 更新时间:2023-11-30 22:20:17 26 4
gpt4 key购买 nike

它应该列出一个列表,并在顶部列出最高百分比..但它没有 https://gyazo.com/ecde864ef09115b8b119eba8a39ecd68这是我运行时的图片

这里是代码。怎么了?

$sql = "SELECT band, concat(round(sum(punten) *100 /
(SELECT sum(punten) FROM bands)) , \"%\") AS percent
FROM bands
WHERE punten>0
GROUP BY band
ORDER BY percent DESC;";

最佳答案

百分比列是一个字符串,因此它们按字典顺序排序(例如,8 被视为大于 26,因为“8”在“2”之后)。相反,您可以在连接之前对数字部分进行排序。这可以通过当前查询来完成,但是将总的 punten 增加到子查询会更优雅:

SELECT     band, CONCAT(ROUND(band_punten) * 100 / total_punten), '%') AS percent
FROM (SELECT band, SUM(punten) AS band_punten
FROM bands
WHERE punten > 0
GROUP BY band) a
CROSS JOIN (SELECT SUM(punten) AS total_punten FROM bands) b
ORDER BY band_punten DESC

关于mysql desc 对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36796688/

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