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


Please Help Members By Posting Answers For Below Questions

What is the difference between in and between in sql?

575


how would you enter characters as hex numbers? : Sql dba

516


How to install oracle sql developer?

566


What is the use of index in sql?

556


What are the two parts of design view?

580






What is record data type?

516


Enlist the characteristics of pl/sql?

1240


Where is sql database stored?

520


What does 0 mean in sql?

528


Why schema is used in sql?

516


What is a variable in sql?

513


How do you concatenate in sql?

551


what is a unique key ? : Sql dba

546


What is form and report?

519


What is data type in database?

545