Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to calculate the total of a varchar column?

Re: How to calculate the total of a varchar column?

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Thu, 16 Feb 2006 07:14:38 +0100
Message-ID: <43f4184d$0$1209$636a55ce@news.free.fr>

"Krishna" <mpkrishna25_at_yahoo.com> a écrit dans le message de news: 1140044911.332349.77810_at_g44g2000cwa.googlegroups.com...
| Hi,
|
| Thanks a lot all for your help. Now I need to interchange the output
| slightly.
| Instead of this
|
| Gender American_Indian
| -----------------------------------------
| M 60
| F 60
| MF 120
|
| I want the output as
| Race Male Female
| -------------------------------------
| Race 1 60 60
| Race 2 70 50
|
| I am getting it separately for each column but I am not able to show
| Male and Female as 2 separate columns.
|
| I've tried the following:
|
|
| SELECT DISTINCT
| DECODE(GENDER, 'M',
| COUNT(GENDER),NULL) MALE
| FROM STUD_DTL
| GROUP BY GENDER;
|
| Not executing giving errors
|
|
| SELECT COUNT(GENDER) MALE and COUNT(GENDER) FEMALE
| FROM STUD_DTL WHERE GENDER = 'M' AND GENDER = 'F'
| ORDER BY GENDER;
|
| SELECT COUNT(GENDER) MALE, COUNT(GENDER) FEMALE
| FROM STUD_DTL WHERE GENDER = 'M' AND GENDER = 'F'
| ORDER BY GENDER;
|
| None of the above commands is working. Can you please help me?
|
| Thank you.
|
| Krish.
|

select sum(decode(gender,'M',1,0)) male,

      sum(decode(gender,'F',1,0)) female,
      sum(decode(gender,'M',0,'F',0,1)) other,
      count(*) total

from stud_dtl
/

Regards
Michel Cadot Received on Thu Feb 16 2006 - 00:14:38 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US