1

私は単純にSQLクエリに従う必要があります。手に入れる方法はありますか??

select * 
  from product a 
  where a.brand_id 
    in (select ib.brand_id from 
      SUBSCRIBED_CHANNEL ia inner join product ib 
      where ia.product_id=ib.product_id and ia.user_id=3)
    and a.product_id not in (select ib.product_id from SUBSCRIBED_CHANNEL ia 
    inner join product ib where ia.product_id=ib.product_id and ia.user_id=3)

編集: 4 つのテーブル:

商品 (PRODUCT_NAME, PRODUCT_ID, BRAND_ID)
SUBSCRIBED_CHANNEL (USER_ID, PRODUCT_ID)
ブランド (BRAND_NAME, BRAND_ID)
ユーザー (..., user_id)

商品からブランド -> 多対 1 の
商品からユーザー -> 多対多の subsubscribed_channel
-> 中間テーブル


Iユーザーがサブスクライブしていない製品を取得する必要があります。
たとえば、Nike ブランドの製品が xx、yy、および zz
で、ユーザーが xx のみを購読している場合、クエリは結果として yy、zz のみを返す必要があります。

4

1 に答える 1