我想请你帮忙。我有两张桌子。在表1中,我有client_num和personal data。我想把tab1和tab2连接起来,其中也有client_nums,但一个客户机号可以在更多行上。本表2的第二列是以数字1-5写成的产品。
表1 CLIENT_NUM;性别
1; M
2; F
3; F
4; M
表2 CLIENT_NUM;产品
1; 2
1; 3
1; 4
2; 1
2; 2
2; 3
3; 4
3; 1
现在我只想要那些没有4号产品的客户
你能帮我一下吗?谢谢
使用不存在
:
select c.*
from clients c
where not exists (select 1
from client_products cp
where cp.client_num = c.client_num and
cp.product = 4
);