SQL中使用和操作的多列数据集

时间:2017-02-24 13:40:05

标签: sql database oracle

原始表数据

Original Table Data

select 
DTRQLFR.DETERMINATION_ID_FK, DTRQLFR.QUALIFIER_ID_FK,   DTRQLFR.QUALIFIER_OPTION_ID_FK 
from IC_DTRMN_QLFR_XREF DTRQLFR
WHERE
(DTRQLFR.QUALIFIER_ID_FK, DTRQLFR.QUALIFIER_OPTION_ID_FK) IN ((1,1), (2,3), (3,6));

查询结果

Query Result

我的要求是需要在数据集上应用操作,如下所示

   ((1,1) AND (2,3) AND (3,6))  ==> need to find  DETERMINATION_ID_FK as 1
   based on (DTRQLFR.QUALIFIER_ID_FK, DTRQLFR.QUALIFIER_OPTION_ID_FK) values

预期结果

Expected Result

1 个答案:

答案 0 :(得分:2)

我认为您正在尝试找到包含所有给定集合的dtrqlfr.determination_id_fk。这样的事情可以奏效:

select 
  DTRQLFR.DETERMINATION_ID_FK
from IC_DTRMN_QLFR_XREF DTRQLFR
where
  (DTRQLFR.QUALIFIER_ID_FK, DTRQLFR.QUALIFIER_OPTION_ID_FK) IN ((1,1), (2,3), (3,6))
group by DTRQLFR.DETERMINATION_ID_FK
having count(*) = 3 -- where 3 is equal to the number of sets 
;