17,089
社区成员
发帖
与我相关
我的任务
分享
SELECT AFROM
(SELECT DISTINCT A FROM TALBE WHERE 条件1 UNION ALL
SELECT DISTINCT A FROM TALBE WHERE 条件2 UNION ALL
SELECT DISTINCT A FROM TALBE WHERE 条件3 UNION ALL
......
SELECT DISTINCT A FROM TALBE WHERE 条件n )
GROUP BY A
HAVING COUNT(1) = n
----------------------------------------------------------------
-- Author :cosio(day day up)
-- Date :2011-10-12 10:25
-- Verstion:
----------------------------------------------------------------
--> 测试数据:[b]
with b
as
(
select 'name1' aa,'address' bb,1 cc from dual
union all
select 'name1','address', 2 from dual
union all
select 'name1','address', 3 from dual
union all
select 'name1','address', 4 from dual
)
select aa,bb from
(
select aa,bb,replace(max(substr(sys_connect_by_path(cc,' '),2)),' ','') dd
from b
start with cc=1
connect by cc=prior cc+1
group by aa,bb
)where dd='1234'
建议思路, 滤重 -> 行转列 -> 过滤
select a,b from (select distinct a,b,type from table1) group by a,b having count(a) = 4 and sum(type) = 10;
select a, b from
(select a,b from test t where exists
(select * from test t1 where t1.a=t.a and t1.b=t.b and t1.type=1) and exists
(select * from test t1 where t1.a=t.a and t1.b=t.b and t1.type=2) and exists
(select * from test t1 where t1.a=t.a and t1.b=t.b and t1.type=3) and exists
(select * from test t1 where t1.a=t.a and t1.b=t.b and t1.type=4))
group by a,b;