I would like to check each store's average score.
My SQL is :
SELECT a.id,a.name,AVG(b.point) as point
from shop a
LEFT JOIN order b on a.id=b.shop_id
WHERE b.point<>0
GROUP BY(b.shop_id)
but this SQL only can check out the shop had point in ‘order’ table.
How can i get whole shop list in SQL?
答案 0 :(得分:3)
Please give this a try:
SELECT
a.id,
a.NAME,
AVG(b.point) AS point
FROM
shop a
LEFT JOIN `ORDER` b ON a.id = b.shop_id AND b.point <> 0
GROUP BY a.id
Since b.shop_id
can be NULL
so that you need to group by a.id
in order to get result for all shop ids.