gpt4 book ai didi

php - PDO mysql 显示 COUNT DISTINCT

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

我试图获取确定的任务类型的数量,但它给了我错误:尝试获取非对象的属性

$statement = $pdo->prepare("SELECT COUNT(DISTINCT Company_Name)
FROM salesplus WHERE `Task_Type` = 'Form Sent'
AND `Consultant_name` = 'Name Surname'");

$statement->execute();
$result=$statement->fetch(PDO::FETCH_OBJ);

foreach($result as $row){
echo $row->Task_Type;

非常感谢!

最佳答案

这不是它的工作原理...尝试(获取确切任务的计数):

SELECT COUNT(*) as count FROM (SELECT DISTINCT Company_Name FROM salesplus WHERE `Task_Type` = 'Form Sent' AND `Consultant_name` = 'Name Surname') as s

或者更好(获取公司列表以及每个公司选定任务的数量):

SELECT `Company_Name`,count(*) as count FROM salesplus WHERE `Task_Type` = 'Form Sent' AND `Consultant_name` = 'Name Surname' GROUP BY `Company_Name`

关于php - PDO mysql 显示 COUNT DISTINCT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39044245/

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