-
A tricky query needed
I have two rows in my table myTable
myTable
Row Name Flag1 Flag2 Number
1 Primary Y N 1234
2 Secondary N Y 4444
I need a query which needs to fetch a single row like this
Row Name Number
1 Primary 4444
The condition is like this
The resultant record should pick the Name iff the Flag1 is Y and the Number iff the Flag2 is Y.
Note: If I use 'Flag1 and Flag2' in my where clause I get don't get any records... If I use 'Flag1 or Flag2' I get two records but I want only one
-
you can use pivot option
1 select max(decode(rownum,1,col1,NULL)) col1
2 ,max(decode(rownum,2,col1,NULL)) col2
3 from (
4 select rownum ,fl1
5 ,case when fl1='Y' then col1 else to_char(val) end col1
6 from foo1
7* )
SQL> /
COL1 COL2
---------------------------------------- -------------------------
primary 4444