如何設置現場most_popular爲0;如果其計數爲null SELECT語句的MySQL如果計數爲null,則使零
我試過IFNULL(SELECT COUNT(*)內的select語句。 ..),0)作爲most_popular,但它不會工作,我嘗試 COALESCE(SELECT COUNT(*)......,0)作爲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");
'SELECT COUNT(*)...'永遠不會產生NULL。嘗試['IF(bool,val_if_true,val_if_false)'](http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if)表達式。 – BlitZ 2013-04-30 03:27:49
你可以給我舉例與我有IF(bool,val1,val2)語句的代碼 – ONYX 2013-04-30 03:28:34