-1
나는 큰 테이블 TRANSACTION 테이블을 가지고, 나는 2015 년 1 월에 대한 키 열을 얻고 싶습니다 그리고 나는 2015 년 1 월에 속하지 않기 때문에 이미 테이블에 존재하는 열을 비교하거나 아니.오라클 SQL 비교 테이블을 분할 할 때
- 기간이! =
2015년 1월 다음 이미 존재하거나하지 않는 열을 모두 비교할 경우 기간 = 2015년 1월
나는 큰 테이블 TRANSACTION 테이블을 가지고, 나는 2015 년 1 월에 대한 키 열을 얻고 싶습니다 그리고 나는 2015 년 1 월에 속하지 않기 때문에 이미 테이블에 존재하는 열을 비교하거나 아니.오라클 SQL 비교 테이블을 분할 할 때
2015년 1월 다음 이미 존재하거나하지 않는 열을 모두 비교할 경우 기간 = 2015년 1월
이 단지 문제의 트랜잭션이 다른 기간 후이 사용되고 있으면 검사의 경우 : 샘플 데이터
가select t1.tdate, t1.key_column,
case
when exists (
select 1 from transactions t2
where t2.key_column = t1.key_column
and t2.tdate not between to_date('2015-01-01', 'yyyy-MM-dd')
and to_date('2015-01-31', 'yyyy-MM-dd')
)
then 'transactions in other months exists'
else 'transactions in other months not found'
end notices
from transactions t1
where t1.tdate between to_date('2015-01-01', 'yyyy-MM-dd')
and to_date('2015-01-31', 'yyyy-MM-dd')
시험 :
with transactions as (
select to_date('2015-01-01') tdate, 17 key_column from dual
union select to_date('2015-01-11') tdate, 123 key_column from dual
union select to_date('2015-01-31') tdate, 90 key_column from dual
union select to_date('2014-06-22') tdate, 17 key_column from dual
union select to_date('2015-02-01') tdate, 19 key_column from dual
union select to_date('2015-02-01') tdate, 90 key_column from dual
)
select t1.tdate, t1.key_column,
case
when exists (
select 1 from transactions t2
where t2.key_column = t1.key_column
and t2.tdate not between to_date('2015-01-01', 'yyyy-MM-dd')
and to_date('2015-01-31', 'yyyy-MM-dd')
)
then 'transactions in other months exists'
else 'transactions in other months not found'
end notices
from transactions t1
where t1.tdate between to_date('2015-01-01', 'yyyy-MM-dd')
and to_date('2015-01-31', 'yyyy-MM-dd')
출력 :
tdate key_column notices
2015-01-01 17 transactions in other months exists
2015-01-11 123 transactions in other months not found
2015-01-31 90 transactions in other months exists
경우를 좀 더 복잡한 방식으로 거래를 비교하고 싶다면 입력, 원하는 출력 및 atte를 첨부하십시오. mpts (있는 경우).
위의 SQL을 사용하면 중복 된 항목을 찾을 수 있습니다. 고마워요. – user1468031