我想创建一个报告,我想通过匹配同一表中2个不同列中的数据来从第3列中获取价值。
Col1 Col2 Col3
123 20190220 456789
456 20180101 789526
789 20190101 623145
101 20181231 589745
我有col1记录和col2记录,我需要一个SQL查询来获取c
答案 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');
答案 1 :(得分:0)
将IN
与元组一起使用:
SELECT c.*
FROM CASES c
WHERE (c.PATIENT_SER, c.CASE_DATE) IN (('168524', '20180101'),
('139016', '20180101'),
. . .
)