求SQL语句 有表Association如下:aid bid 1 1 2 1 3 2 4 2 5 3 ......求一SQL语句,得到所有与aid(1,2)同时存在关联的bid 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select bidfrom Association awhere a.aid = 1and exists( select 1 from Association b where b.aid = 2 and a.bid = b.bid) (1, 2)只是个例子,这个序列是不固定的,可以描述为(e0, e1, e2... en) select a.bid from Association a,Association bwhere a.bid=b.bid and a.aid=1 and b.aid=2; select bid from(select distinct bid from tb where aid = 1union allselect distinct bid from tb where aid = 2) tgroup by bid having count(1) > 1 就是存在aid bid 1 x 2 x这样的记录 select bid from associationwhere aid in (e0, e1, e2... en)group by bidhaving count(distinct aid)=N select bid from association where aid in (e0, e1, e2... en) group by bid having count(distinct aid)=N 如何避免自治事务的死锁? oracle 一条sql查询出价格在各个区间的统计 /etc/rc.local无法正确使用chmod和chown命令 我的job为啥不运行 oracle 9i For Linux 的字符集的问题,谢绝灌水! 多表联接查询(5个表) oracle performance manager数据库乱码??急! asp中如何连接oracle数据库,在线 怎样搭建一个大型ORACLE数据库?高手指点。 那裡可以下載完整的<<oracle 初學者指南>>. 不同数据库间保存数据问题? oracle小问题
from Association a
where a.aid = 1
and exists(
select 1 from Association b
where b.aid = 2 and a.bid = b.bid
)
where a.bid=b.bid and a.aid=1 and b.aid=2;
(
select distinct bid from tb where aid = 1
union all
select distinct bid from tb where aid = 2
) t
group by bid having count(1) > 1
aid bid
1 x
2 x
这样的记录
where aid in (e0, e1, e2... en)
group by bid
having count(distinct aid)=N
where aid in (e0, e1, e2... en)
group by bid
having count(distinct aid)=N