0
我的MySQL查詢:MySQL的COUNT(子查詢)
SELECT id, name, depth, restricted, order, parent_id,
(SELECT COUNT(t2.id) AS count FROM #__webshop_product_color_dbar AS t2
WHERE t2.product_id =
(SELECT product_id FROM #__webshop_category_product AS t3
WHERE t3.category_id = "0")
AND available < 0 OR stock = "Y" OR infinite_amount = "Y"
) AS productcount
FROM #__webshop_category AS t1
WHERE parent_id = "'.$parent_id.'" AND depth = "'.$depth.'" AND restricted="N"
ORDER BY id ASC
我的問題是:所有的產品數= 2; 如果我使用「WHERE t2.product_id IN」,它不起作用。
什麼問題?
(對不起我的英文不好)
難道你不能做一個加入,然後通過一組來獲得你想要的? – 2011-05-06 08:10:34
爲什麼這麼複雜? – diEcho 2011-05-06 08:12:18
從3個表中檢索數據,並在類別產品計數<0時用parent_id-s和深度生成類別樹。爲什麼更好地加入以及如何做到這一點? – sodey 2011-05-06 08:21:32