Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to calculate the total of a varchar column?
"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
Regards
Michel Cadot
Received on Thu Feb 16 2006 - 00:14:38 CST