用户在该产品的书签中有一个查询,也考虑了该产品的点赞,并在表中显示所有产品:
SELECT P.*,
COUNT(L.USER_ID) AS LIKES,
(B.PRODUCT_ID = P.PRODUCT_ID AND B.USER_ID = B.USER_ID) AS BOOKMARKS
FROM PRODUCTS AS P
LEFT JOIN LIKES_PRODUCTS AS L ON (L.PRODUCT_ID = P.PRODUCT_ID)
LEFT JOIN BOOKMARKS_PRODUCTS AS B ON (B.PRODUCT_ID = P.PRODUCT_ID)
GROUP BY P.PRODUCT_ID, B.PRODUCT_ID, B.USER_ID ORDER BY P.PRODUCT_ID
但是他将产品添加到产品中的现有产品中,并且不显示false
,而仅显示 ,并对其位置进行true
错误显示:null
product_id | product_name | ... | LIKES | BOOKMARKS |
------------------------------------------------------
1 | name 1 | ... | 0 | true |
1 | name 1 | ... | 0 | true |
2 | name 2 | ... | 0 | NULL |
3 | name 3 | ... | 0 | NULL |
4 | name 4 | ... | 0 | NULL |
为什么他给我加了一个额外的产品 1 并且不显示书签栏false
,但它有null
吗?我哪里错了请帮帮我。