gpt4 book ai didi

mysql - 更新 PDO 查询的选项

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

我如何更新此查询?我尝试获取包含超过 1 个产品的所有类别,计算这些产品在她身边显示的数量,但我的查询太慢(2 秒)。如果可能的话,我如何做同样的事情,但速度更快?

SELECT
C.id, C.name, C.id_dept, C.cat_type, C.num_prod
FROM
(SELECT
C.id, C.name, C.id_dept, C.cat_type,
COALESCE((SELECT count(P.id) FROM Products P WHERE P.status = 1 AND P.promo = 1 AND P.id_cat = C.id ), 0) AS num_prod
FROM
Products_Cat C
) C
WHERE
C.num_prod > 0 AND C.cat_type = 1 AND C.id_dept = '{IDD}'
ORDER BY C.name ASC

最佳答案

更新 PHP PDO

$sql = $db->prepare("UPDATE `Products` set `name` = :name,  `id_dept` = :id_dept, `cat_type` = :cat_type WHERE status = 1 AND promo = 1);
//bind all parameters
$sql->bindParam(':name',$name);
.
.
.
$sql->execute();

关于mysql - 更新 PDO 查询的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35820843/

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