通过在SQL加两个值来搜索第三列

时间:2019-02-21 14:21:56

标签: sql oracle

我想创建一个报告,我想通过匹配同一表中2个不同列中的数据来从第3列中获取价值。

Col1           Col2              Col3

 123        20190220           456789

 456        20180101           789526

 789        20190101           623145

101        20181231           589745

我有col1记录和col2记录,我需要一个SQL查询来获取c

2 个答案:

答案 0 :(得分:0)

在您要寻找的东西以下-

select * FROM CASES WHERE 
(PATIENT_SER = '168524' and CASE_DATE ='20180101')
or
(PATIENT_SER = '139016' and CASE_DATE ='20180101')
or
(PATIENT_SER = '64685' and CASE_DATE ='20180104')
or
(PATIENT_SER = '168585' and CASE_DATE ='20180104')
or
(PATIENT_SER = '168740' and CASE_DATE ='20180105')
or
(PATIENT_SER = '14507' and CASE_DATE ='20180105');

预期结果-http://sqlfiddle.com/#!4/082368/6

答案 1 :(得分:0)

IN与元组一起使用:

SELECT c.*
FROM CASES c
WHERE (c.PATIENT_SER, c.CASE_DATE) IN (('168524', '20180101'),
                                       ('139016', '20180101'),
                                       . . .
                                      )