gpt4 book ai didi

Mysql select count on left join with condition not working 条件不工作

转载 作者:行者123 更新时间:2023-11-29 04:45:15 24 4
gpt4 key购买 nike

我需要计算左表上的记录数,我阅读了其他问题并以这个查询结束,但忽略了 COUNT 条件

SELECT  a.name, COUNT( f.status <> 'e' ) AS total               
FROM album AS a LEFT JOIN photo AS f
ON a.id = f.idalbum
WHERE a.iduser = 4
GROUP BY a.id

是 MySQL 5 数据库

最佳答案

您不能在 COUNT 语句中指定条件。

试试这个

   SELECT  a.name, COUNT( f.status  ) AS total               
FROM album AS a LEFT JOIN photo AS f
ON a.id = f.idalbum
WHERE a.iduser = 4 or f.status <> 'e'
GROUP BY a.id

关于Mysql select count on left join with condition not working 条件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20030127/

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