I need to create a table of values similar to this:
Each "(count)" above is computed by passing date/offest parameters to a stored function which queries the database and returns the count of records that satisfy the particular condition for the particular date.
I need to come up with a way to 1) sum all values, 2) sum selected values, 3) compute a percentage.
It all has to go into a single SQL statement inside a 3rd party application. FWIW, the first "Select" statment has to be generated by the wizard, so I put a "where 1 = 2" condition to ignore it. I then continue with a series of "UNION"s to produce the lines like this:
I could do my total/percent calculations by invoking the functions all over again and add, multiply, divide, and otherwise calculate my needed totals, but 1) it churns up too much time, and 2) that seems really clunky. :-(
I'm not very savvy with SQL just yet, so another approach, perhaps a stored procedure, might serve the purpose if I could figure out how to return a count and save it for computation at the same time.
The database is Oracle9i.
Many thanks in advance.
Code:
Category Month 1 Month 2 Month 3
Condition 1 (count) (count) (count)
Condition 2 (count) (count) (count)
Condition 3 (count) (count) (count)
Total of all (sum) (sum) (sum)
Total of 2&3 (sum) (sum) (sum)
Ratio of sum (%) (%) (%)
to (condition 1
plus condition 3)
Each "(count)" above is computed by passing date/offest parameters to a stored function which queries the database and returns the count of records that satisfy the particular condition for the particular date.
I need to come up with a way to 1) sum all values, 2) sum selected values, 3) compute a percentage.
It all has to go into a single SQL statement inside a 3rd party application. FWIW, the first "Select" statment has to be generated by the wizard, so I put a "where 1 = 2" condition to ignore it. I then continue with a series of "UNION"s to produce the lines like this:
Code:
UNION
select '1'
, 'Closed Early'
,TSO_UDF.stat_closed_early(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), -1)
,TSO_UDF.stat_closed_early(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), 0)
,TSO_UDF.stat_closed_early(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), 1)
from dual
UNION
select '2'
, 'Closed On Time'
,TSO_UDF.stat_closed_on_time(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), -1)
,TSO_UDF.stat_closed_on_time(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), 0)
,TSO_UDF.stat_closed_on_time(TO_DATE('[PARM_DATE]', 'YYYY-MM-DD HH24-MI-SS'), 1)
from dual
etc.
I could do my total/percent calculations by invoking the functions all over again and add, multiply, divide, and otherwise calculate my needed totals, but 1) it churns up too much time, and 2) that seems really clunky. :-(
I'm not very savvy with SQL just yet, so another approach, perhaps a stored procedure, might serve the purpose if I could figure out how to return a count and save it for computation at the same time.
The database is Oracle9i.
Many thanks in advance.