Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PL/SQL Multiple PAYER_IDs with PAYER_TYPES are these types

Posted on 2016-10-18
3
Medium Priority
?
56 Views
Last Modified: 2016-10-19
Hello expert,

Thanks to slightWv for the excellent solution copied herewith below
marked '-- Two PAYER_TYPE_CODES'.

Successfully extended  
..................
count(case when payer_type_code = 17001 then 1 end) has_17001,
count(case when payer_type_code = 17002 then 1 end) has_17002,
count(case when payer_type_code = 17003 then 1 end) has_17003,
             count(*) total_count
       from CCM_PAYER_TYPE
       group by payer_id
 )
 where total_count=3 and has_17001=1 and has_17002=1 and has_17003=1

to three PAYER_TYPE_CODE s

But when the pattern was used to extend to four PAYER_TYPE_CODE s,
marked  "-- Two PAYER_TYPE_CODES" copied herewith below,
the query returns zero rows.

Why will the pattern not extend past three?

Thanks.


Allen in Dallas



-- Two PAYER_TYPE_CODES
  with CTE as
 (
 select payer_id from (
       select payer_id,
             count(case when payer_type_code = 17001 then 1 end) has_17001,
             count(case when payer_type_code = 17002 then 1 end) has_17002,
             count(*) total_count
       from CCM_PAYER_TYPE
       group by payer_id
 )
 where total_count=2 and has_17001=1 and has_17002=1
 )
 SELECT
 CTE.PAYER_ID,
 PAYER_TYPE_CODE
 from CTE
 join CCM_PAYER_TYPE PAT on CTE.PAYER_ID = PAT.PAYER_ID


-- Four PAYER_TYPE_CODES
with CTE as
(
 select payer_id from (
       select payer_id,
             count(case when payer_type_code = 17001 then 1 end) has_17001,
             count(case when payer_type_code = 17002 then 1 end) has_17002,
             count(case when payer_type_code = 17003 then 1 end) has_17003,
             count(case when payer_type_code = 17004 then 1 end) has_17004,
             count(*) total_count
       from CCM_PAYER_TYPE
       group by payer_id
 )
 where total_count=4 and has_17001=1 and has_17002=1 and has_17003=1 and has_17004=1
 )
 SELECT
 CTE.PAYER_ID,
 PAYER_TYPE_CODE
 from CTE
 join CCM_PAYER_TYPE PAT on CTE.PAYER_ID = PAT.PAYER_ID
0
Comment
Question by:Allen Pitts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:Allen Pitts
ID: 41849101
Hello Expert,

I have discovered why the extension of the ....count(case... statement did
not extend to four cases. The data did not have four cases, at least not where
the PAYER_TYPE s were 17001, 17002, 17003, 17004.

So tried group by PAYER_ID where count(*) =4 and found a payer with four PAYER_TYPE s
and then reworked the ....count(case... using those PAYER_TYPE s. So it would seem
reasonable that the ...count(case... construct does work.

Thanks.

Allen in Dallas
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 41849155
A lot depends on your exact requirements.  I took the previous question to mean you want payers with ONLY TWO codes and one each of 17001 and 17002.

If you look at my test data, there were others that had two codes but they weren't one each of the two you provided.

If you remove the count and case you might get payers with 4 of all 17001's.

If that doesn't matter, then the query can probably be even simpler.

We just need to know the exact requirements.
0
 

Author Closing Comment

by:Allen Pitts
ID: 41850156
Hello SlightWV,

Excellent answer. Yes you are correct. The requirement s are
1. That there be two PAYER_TYPE_CODE s
and
2. Those two codes should be 17001and 17002

Also used suggestions on eliminating the ' WithCTE as'

Thanks.

Allen
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question