这是我的查询:
SELECT
i.item,
COALESCE(COUNT(r.item_id), 0) AS TotalRating,
SUM(r.rating) as RatingSum,
re.tR as TotalReview,
AVG(r.rating) AS AverageRating
FROM items AS i
LEFT JOIN ratings AS r
ON (r.item_id = i.item_id)
LEFT JOIN
(SELECT item_id,COALESCE(COUNT(item_id),0) AS tR
FROM reviews
WHERE item_id = '{$itemId}') AS re
ON re.item_id = i.item_id
WHERE i.item_id = '{$itemId}';
我不断收到此错误:
#1048 - Column 'item_id' cannot be null
该行与 table 的子查询有关reviews
。我正在使用Coalesce
;为什么它仍然说它为空?