从表中检索数据
To Retrieve data from tables
我有两个table
Table一个
Cust_ID | Channel_CODE
Table B
Channel_code | Channel_name
我想要 cust_id
没有订阅的所有 channel_codes
和 channel_names
。
假设在 table B 中我们有
101 | Discovery_channel
然后我想要除客户 ID 101 的发现渠道之外的所有其他渠道。
提前致谢。
您可以为此使用 JOIN 和 NOT IN():
SELECT t.Cust_ID,s.Channel_code,s.Channel_name
FROM (select distinct cust_id from TableA) t
INNER JOIN TableB s ON(1=1)
WHERE s.Channel_code NOT IN(select f.Channel_code from TableA f
WHERE f.Cust_ID = t.Cust_ID)
这将为您提供 customer_id 未观看的所有 channel_codes
我有两个table
Table一个
Cust_ID | Channel_CODE
Table B
Channel_code | Channel_name
我想要 cust_id
没有订阅的所有 channel_codes
和 channel_names
。
假设在 table B 中我们有
101 | Discovery_channel
然后我想要除客户 ID 101 的发现渠道之外的所有其他渠道。
提前致谢。
您可以为此使用 JOIN 和 NOT IN():
SELECT t.Cust_ID,s.Channel_code,s.Channel_name
FROM (select distinct cust_id from TableA) t
INNER JOIN TableB s ON(1=1)
WHERE s.Channel_code NOT IN(select f.Channel_code from TableA f
WHERE f.Cust_ID = t.Cust_ID)
这将为您提供 customer_id 未观看的所有 channel_codes