Home » Developer & Programmer » Forms » getting values of some column and comparing it. (oracle 10g, windows XP)
getting values of some column and comparing it. [message #469852] Fri, 06 August 2010 02:27 Go to next message
myclassic
Messages: 136
Registered: December 2006
Location: Pakistan
Senior Member
Dear i have got a table having column a, b , c, d, e
and some values are stored in it. e.g. a, c and e have 'Y' and b and d have 'N' value in it.

how can i count with one query , how many columns have 'Y' and how many have 'N'.

cursor is one solution...

can anyone suggest some other solution.

waiting for responce.

regards.
Re: getting values of some column and comparing it. [message #469857 is a reply to message #469852] Fri, 06 August 2010 02:45 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here it is:
SQL> select * from test;

A B C D E
- - - - -
Y N Y N N

SQL> select length(replace(str, 'N', '')) number_of_Y,
  2         length(replace(str, 'Y', '')) number_of_N
  3  from (select a||b||c||d||e str
  4        from test
  5       );

NUMBER_OF_Y NUMBER_OF_N
----------- -----------
          2           3

SQL>
Re: getting values of some column and comparing it. [message #469871 is a reply to message #469857] Fri, 06 August 2010 03:28 Go to previous message
myclassic
Messages: 136
Registered: December 2006
Location: Pakistan
Senior Member
thanks dear...

this is what i wanted.

regards.
Previous Topic: record error
Next Topic: Migrating from oracle 8i to oracle 10g
Goto Forum:
  


Current Time: Thu Sep 19 17:18:05 CDT 2024