gpt4 book ai didi

php - 获取具有值的列的百分比

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

我试着这样做:

 SELECT (SELECT COUNT(*)
FROM users WHERE email != '') / (SELECT COUNT(*) FROM users)

但它在 php Operand should contain 1 column(s) 中给了我这个错误,在 mysql 中一切正常。还有其他解决方案吗?

EDIT : its not exactly like that I had also groups by months, the above query works but the accepted answer solves my error

最佳答案

您可以在单个查询中完成:

SELECT SUM(email != '') / COUNT(*) 
AS ratio
FROM users

...或者,如果您需要百分比:

SELECT 100 * SUM(email != '') / COUNT(*)
AS percentage
FROM users

关于php - 获取具有值的列的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22831804/

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