如果在 select 语句中使用 select 语句,它的计数为 null,如何将字段 most_popular 设置为 0
我试过 IFNULL(SELECT COUNT(*) ...), 0) as most_popular 但它不起作用,我试过 COALESCE(SELECT COUNT(*) ...., 0) as most_popular
$stmt = $db->prepare("SELECT *,
i.medium_image, i.width, i.height,
(SELECT COUNT(*) FROM order_details od WHERE od.product_id = p.product_id) as most_popular
FROM products p
INNER JOIN product_images i on i.product_id = p.product_id
WHERE p.department_id=:department_id AND p.is_active=1
$orderby
LIMIT :limit OFFSET :offset");