Hello
I am trying to do a subquery within a select statement that access the field from the outer select. Is that possible? I tried it and it did not work. Below is I hope a simple example of what I am trying to do.
SELECT table1.field1 alias1,
table1.field2 alias2,
table1.field3 alias3,
(SELECT table2.field1
FROM table2
WHERE table2.field2 = <value from field2 of the outer Select statement>
AND table2.field3 = <value from field3 of the outer Select statement>
AND table2.field4 = 'OPEN'
) alias4,
table1.field4 alias5,
( ( (SUM(DECODE(field6,9, amount, 0) ) ) +
(SUM(DECODE(field6,10, amount, 0) ) )
) -
( (SUM(DECODE(field6,15, amount, 0) ) ) +
(SUM(DECODE(field6,17, amount, 0) ) ) +
(SUM(DECODE(field6,18, amount, 0) ) ) +
(SUM(DECODE(field6,19, amount, 0) ) )
)
) alias6
FROM table1
GROUP by table1.field1, table1.field2, table1.field3, table1.field4;
The subquery needs to send back only one row due to the Group by.
Thanks
getjbb
I am trying to do a subquery within a select statement that access the field from the outer select. Is that possible? I tried it and it did not work. Below is I hope a simple example of what I am trying to do.
SELECT table1.field1 alias1,
table1.field2 alias2,
table1.field3 alias3,
(SELECT table2.field1
FROM table2
WHERE table2.field2 = <value from field2 of the outer Select statement>
AND table2.field3 = <value from field3 of the outer Select statement>
AND table2.field4 = 'OPEN'
) alias4,
table1.field4 alias5,
( ( (SUM(DECODE(field6,9, amount, 0) ) ) +
(SUM(DECODE(field6,10, amount, 0) ) )
) -
( (SUM(DECODE(field6,15, amount, 0) ) ) +
(SUM(DECODE(field6,17, amount, 0) ) ) +
(SUM(DECODE(field6,18, amount, 0) ) ) +
(SUM(DECODE(field6,19, amount, 0) ) )
)
) alias6
FROM table1
GROUP by table1.field1, table1.field2, table1.field3, table1.field4;
The subquery needs to send back only one row due to the Group by.
Thanks
getjbb