AndersonCJA
Programmer
Hi,
I would like to use the decode statement instead of subqueries.
The only difference between each subquery below is the value that is checked in fld3 and fld4.
The query pulls the amount for that value for the keyfield in each query.
The field names have been changed to submit this post, but prior to that the query will run in sql talk and produce the results I want.
How can it be changed to use the decode statement instead of the subqueries? I am using Oracle 10g.
the query returns subquery_a Through F in a line that looks like this.
sub_a Sub_b sub_c sub_d sub_e sub_f
$10.15 $20.00 $3.35 $4.50 $2.00 $40.00
SELECT
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
A1 A1, A2 A2, A3 A3, A4 A4
WHERE
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'AAA' AND
A4.fld4 = 'AA' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_A
(SELECT
LTRIM(TO_CHAR( SUM(A3.Amt), '$999,999.99'))
FROM A1 A1, A2 A2, A3 A3, A4 A4
WHERE
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'BBB AND
A4.fld4 = 'BB’ AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_B
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'CCC' AND
A4.fld4 = 'CC' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_C ,
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'dddd' AND
A4.fld4 = 'dd' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_d,
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'EEE' AND
A4.fld4 = 'EE' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_E,
(SELECT
LTRIM(TO_CHAR( SUM(A3.Amt), '$999,999.99'))
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_F
FROM
DUAL
Thank you so much for your help. I just can't figure it out and this query doesn't work in the environment I need it to.
I would like to use the decode statement instead of subqueries.
The only difference between each subquery below is the value that is checked in fld3 and fld4.
The query pulls the amount for that value for the keyfield in each query.
The field names have been changed to submit this post, but prior to that the query will run in sql talk and produce the results I want.
How can it be changed to use the decode statement instead of the subqueries? I am using Oracle 10g.
the query returns subquery_a Through F in a line that looks like this.
sub_a Sub_b sub_c sub_d sub_e sub_f
$10.15 $20.00 $3.35 $4.50 $2.00 $40.00
SELECT
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
A1 A1, A2 A2, A3 A3, A4 A4
WHERE
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'AAA' AND
A4.fld4 = 'AA' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_A
(SELECT
LTRIM(TO_CHAR( SUM(A3.Amt), '$999,999.99'))
FROM A1 A1, A2 A2, A3 A3, A4 A4
WHERE
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'BBB AND
A4.fld4 = 'BB’ AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_B
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'CCC' AND
A4.fld4 = 'CC' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_C ,
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'dddd' AND
A4.fld4 = 'dd' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_d,
(SELECT
LTRIM(TO_CHAR(A3.Amt, '$999,999.99'))
FROM
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A4.fld3= 'EEE' AND
A4.fld4 = 'EE' AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_E,
(SELECT
LTRIM(TO_CHAR( SUM(A3.Amt), '$999,999.99'))
(A1.fld1key = A2.fld1key AND
(A1.fld1key=A3.fld1key) AND
((A3.fld1key=A4.fld1key) AND
(A3.fld2=A4.fld2)) AND
A3.fld1key = uniquevalue AND
A2. Date = A3.Date) sub_F
FROM
DUAL
Thank you so much for your help. I just can't figure it out and this query doesn't work in the environment I need it to.