Sathish David Kumar N
asked on
is it possible to use query inside the DECODE()
is it possible to use query inside the DECODE()
SELECT MAX(DECODE(grp, 'n1', (select max(n1) from xxx a,xxx b a.grp=b.grp)
, 'n2', n2, 'n3', n3, 'n4', n4))
FROM xxx b
like this
SELECT MAX(DECODE(grp, 'n1', (select max(n1) from xxx a,xxx b a.grp=b.grp)
, 'n2', n2, 'n3', n3, 'n4', n4))
FROM xxx b
like this
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window
I recommend to use this instead, as using a subquery in the select list can perform bad:Open in new window
I suppose the query is constructed, as a max(max(...)) doesn't make much sense, in particular if applied to the same table xxx. Since the max(n1) part is only used if grp = 'n1', we could restrict each subquery to exactly that: where grp = 'n1'.