我有两张桌子。
表1
Claim_id
Claim_Status -- Includes values of "PAID" and "DENIED"
表2 - 此表包含表1中的相同声明,但包含行项目详细信息。
Claim_id
Line_number
Status -- Includes values of "PAID" and "DENIED"
表1中的PAID状态claim_id
可能包含Status
=" DENIED"来自表2
特定的付费索赔可能很少被拒绝。
我需要提取所有行所在的声明数量" PAID"状态,
和某些行是" PAID"并且有些行已经过了#34; DENIED"对于给定的claim_id
。
SELECT x.claim_id, x.claim_status, x.payer_id1
FROM HEADER_CLAIM_TABLE x
WHERE x.payer_id1 = 'company_Z'
AND x.claim_id in (SELECT a.CLAIM_ID,
a.LINE_NUMBER,
a.STATUS,
a.payer_id
FROM LINE_DETAIL_CLAIM_TABLE a
WHERE EXISTS (SELECT b.*
FROM LINE_DETAIL_CLAIM_TABLE B
WHERE b.status = 'DENIED')
AND a.claim_id = b.claim_id
AND a.line_number = b.line_number
AND a.payer_id = b.payer_id)
AND x.claim_status = 'PAID'
我是新手,请原谅上述查询是否完全偏离了。请帮助我们提取这些数据。
谢谢。
答案 0 :(得分:0)
这是一些旧式的sql ..试着这个
select claim_with_no_deny.cnt PAID_COUNT, claim_with_deny.cnt WITH_DENY_COUNT
from
(select count(*) cnt from HEADER_CLAIM_TABLE h where
exists (select 1 from LINE_DETAIL_CLAIM_TABLE D where h.claim_id=d.claim_id and d.status = 'DENIED') claim_with_deny,
(select count(*) cnt from HEADER_CLAIM_TABLE h where
not exists (select 1 from LINE_DETAIL_CLAIM_TABLE D where h.claim_id=d.claim_id and d.status = 'DENIED') claim_with_no_deny