以下的SQL需求如何实现,急求

0
现在有表A,字段有id和at_id,表B有字段id,表A的at_id下有各种属性值,现在要求找到表A下的相同字段id同时含有at_id的5个属性,必须满足, 比如10,11,12,13,14,15,这里应该不能用in(10,11,12,13,14,15)吧,应该如何写,麻烦开发高手指导写下,谢谢。
 
数据库:Oracle
已邀请:
1

天善_小龙 2016-04-07 回答

参考以下例子,看符合你的要求不:
select * from (with temp as( 
  select  '100' id ,'10' at_id from dual union all 
  select  '100' id ,'11' at_id from dual union all 
  select '100' id ,'12' at_id from dual union all 
  select  '100' id ,'13' at_id from dual union all 
  select  '100' id ,'14' at_id from dual union all 
  select '100' id ,'15' at_id from dual  union all 
  select '101' id ,'10' at_id from dual  union all
  select '101' id ,'11' at_id from dual  union all
  select '101' id ,'12' at_id from dual  union all
  select '101' id ,'13' at_id from dual  union all
  select '101' id ,'14' at_id from dual  union all
  select '101' id ,'15' at_id from dual  union all 
  select '102' id ,'11' at_id from dual  union all 
  select '102' id ,'12' at_id from dual  union all
  select '102' id ,'13' at_id from dual  union all
  select '102' id ,'14' at_id from dual

select
       id, 
       at_id, 
       listagg(at_id,',') within GROUP (order by at_id) over (partition by id) rank 
from temp)a 
where a.rank='10,11,12,13,14,15';
 

111.PNG

 
0

牟瑞 - 大数据 Hadoop 讲师 Hadoop入门课程地址:http://www.hellobi.com/course/39 有架构师,技术总监,CTO的职位请联系我! 2016-04-07 回答

给你邀请了Oracle的专家!
 
0

老头子 - 专注是唯一的捷径 2016-04-07 回答

业务逻辑能说清楚点不,
A表如下数据,则吧ID=1取出? AT_ID一共有几种属性?最多就6种么?
ID   |AT_ID
1    |10
1    |11
1    |12
1    |13
1    |14
1    |15
2    |13
2    |14
3    |11
4    |11
4    |12
4    |13
4    |14
 
0

GeorgeYao - 路漫漫其修远兮,吾将上下而求索! 2016-04-07 回答

楼主@微软BI ,你的脚本是在Oracle的哪个版本中run的。
0

jason_lew - 关注BI 2016-04-08 回答

这两个例子是否符合,供参考
 
a3.jpg

a2.jpg


 

 

要回复问题请先登录注册