Table name: T1, it has only one column.
col1
------
c
b
a
b
b
b
b
d
s
a
a
t
s
Requirement:
I need the following output from the above base table by
using SQL query.
col1 Cnt
----- -------
a 3
b 5
Others 5
Please help.
Thanks
Guru
v.gurus@in.com
Answer Posted / vivek nagarajan
SELECT SUM(DECODE(txt,'a',1)) a_count,
SUM(DECODE(txt,'b',1)) b_count,
SUM(DECODE(txt,'a',0,'b',0,1)) others_count
FROM t1;
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
How do I pipe the output of one isql to another?
What is meant by user defined function?
What is the purpose of a secondary key?
How would you reference column values before and after you have inserted and deleted triggers?
what is the difference between cluster and non cluster index? : Sql dba
explain primary keys and auto increment fields in mysql : sql dba
What is field delimiter?
What is a schema? How is it useful in sql servers?
what is the bond code in materialized view?
What is the difference between between and in condition operators?
Which one is better subquery or joins?
What is t sql used for?
How do you clear the screen in sql?
What is minus?
What is sp_helptext?