SpeedThink
MIS
I am interested in creating a Matrix Report in SQLPlus that will result in a count of accounts for several contracts
that had a particular diagnosis grouped by month not individual dates within the month from April 22, 2002 through August
11, 2002.
Currently, I am thinking about doing this in two steps;
1st, query the database using a business intelligence application such as Brio to obtain all of the records for the contracts (CID) with all of the individual discharge dates from April 22, 2002 through August 11, 2004 (over 100,000 records!) and then import into Microsoft Excel and perform a pivot and group by month. Due to the time involved, there must be a more efficient way considering that I need to perform this every week!
For example,
CID Account Discharge_date
X24 1234B April 1, 2002
X24 1234C April 2, 2002
X24 1234D April 3, 2002
X25 2464A April 1, 2002
.
.
.
Is there a more efficient method within SQLPlus that would utilize the "decode" method or the "case" method?
For example, I am comtemplating something involving the following decode statement as shown below:
Select *
from (select distinct account_id,
count(decode (discharge_date, '22-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '23-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '24-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '25-Apr-02', account_no)) April 2002 ...
from patient_encounter
where account_id in ('X24','X25')
Group by account_id, month)
order by 1;
Using Case Statements:
Select contract_id, CASE WHEN discharge_date between '22-Apr-02' and '30-Apr-02' THEN 'April 2002'
.
.
.
Results should be like this:
CID April 2002 May 2002 June 2002
X24 20,000 300,000 250,000
X25 15,000 200,000 500,000
X26 28,000 150,000 200,000
Any insight?
Thanks in advance.
that had a particular diagnosis grouped by month not individual dates within the month from April 22, 2002 through August
11, 2002.
Currently, I am thinking about doing this in two steps;
1st, query the database using a business intelligence application such as Brio to obtain all of the records for the contracts (CID) with all of the individual discharge dates from April 22, 2002 through August 11, 2004 (over 100,000 records!) and then import into Microsoft Excel and perform a pivot and group by month. Due to the time involved, there must be a more efficient way considering that I need to perform this every week!
For example,
CID Account Discharge_date
X24 1234B April 1, 2002
X24 1234C April 2, 2002
X24 1234D April 3, 2002
X25 2464A April 1, 2002
.
.
.
Is there a more efficient method within SQLPlus that would utilize the "decode" method or the "case" method?
For example, I am comtemplating something involving the following decode statement as shown below:
Select *
from (select distinct account_id,
count(decode (discharge_date, '22-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '23-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '24-Apr-02', account_no)) April 2002,
count(decode (discharge_date, '25-Apr-02', account_no)) April 2002 ...
from patient_encounter
where account_id in ('X24','X25')
Group by account_id, month)
order by 1;
Using Case Statements:
Select contract_id, CASE WHEN discharge_date between '22-Apr-02' and '30-Apr-02' THEN 'April 2002'
.
.
.
Results should be like this:
CID April 2002 May 2002 June 2002
X24 20,000 300,000 250,000
X25 15,000 200,000 500,000
X26 28,000 150,000 200,000
Any insight?
Thanks in advance.