[步骤]
红人检索页,关联商品,数量显示不正确[结果]



对不上的商品名称:
数据库有,页面没有的:
2GB PNY Mini SD卡
页面有,数据库没有的:
10440 3.6V 500MAH 2粒
确认下我的sql 是否是正确的
-- 红人检索页面 关联商品的数量
SELECT t_celebrity_product.product_name
FROM t_celebrity_product_relation
INNER JOIN t_celebrity_product ON t_celebrity_product_relation.product_id = t_celebrity_product.ID
WHERE t_celebrity_product_relation.celebrity_id IS NOT NULL AND t_celebrity_product.is_actived = 1;
[期望]
显示正确

这里的关联商品应该展示当前登录账号下所绑定的商品,也就是在新增商品时,这个商品绑定的BD专员。
t_celebrity_product_relation这张表是存的是BD专员与红人关于某一个商品的建联关系,必须至少要已发信状态才会产生一条数据。
t_celebrity_product_contacts这张表存的是商品也BD专员绑定的数据,也就是在新增商品时,这个商品绑定的BD专员。这里就会产生一条数据。
所以sql查询应该关联t_celebrity_product_contacts这张表,而不是t_celebrity_product_relation这张表。
---------------------
sql如下:(其中c.contacts_id = 2 是指当前登录的账号的id为2,在t_celebrity_team_user这张表可看到)
SELECT DISTINCT
p.id,
p.product_name,
p.product_image,
p.product_class_id,
p.product_class_id_1,
p.product_class_id_2,
p.product_link_url,
p.sku,
p.brand_id,
p.shop_id
FROM
t_celebrity_product p
LEFT JOIN t_celebrity_product_contacts c ON c.product_id = p.id
WHERE
p.is_deleted = 0
AND p.is_actived = 1
AND c.contacts_id = 2
AND c.is_deleted = 0