求帮助写一个外连接SQL!!!!!!!!外连接,或者子查询~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sql
求帮助写一个外连接SQL!!!!!!!!外连接,或者子查询~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sql 建表语句:
[解决办法]
试一下
第一问:
select *
from txt_base a
where a.f_f_id not in
(select distinct b.f_f_id from txt_base b where b.f_lan_id = 2);
第二问:
select *
from txt_base a
where a.f_f_id not in
(select distinct b.f_f_id from txt_base b where b.f_lan_id in (3));
我是用oracle试验的,部分字段你转一下
[解决办法]
3楼的就可以了,顶3楼!
[解决办法]
问题是不是没描述清楚,如果描述清楚的话,直接从lan_id查询就行了。说实话搞不懂你的问题
[解决办法]
select * from txt_base t
where exists(select 1 from txt_base a where a.lan_id=1 and t.f_id = a.f_id) and not exists(select 1 from txt_base b where b.lan_id = 2 and t.f_id = b.f_id);
select * from txt_base t
where exists(select 1 from txt_base a where a.lan_id=1 and t.f_id = a.f_id)
and exists(select 1 from txt_base c where c.lan_id=2 and t.f_id = c.f_id)
and not exists(select 1 from txt_base b where b.lan_id = 3 and t.f_id = b.f_id);
------解决方案--------------------
select * from txt_base t
where exists(select 1 from txt_base a where a.lan_id=1 and t.f_id = a.f_id) and not exists(select 1 from txt_base b where b.lan_id = 2 and t.f_id = b.f_id);
select * from txt_base t
where exists(select 1 from txt_base a where a.lan_id=1 and t.f_id = a.f_id)
and exists(select 1 from txt_base c where c.lan_id=2 and t.f_id = c.f_id)
and not exists(select 1 from txt_base b where b.lan_id = 3 and t.f_id = b.f_id);
