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 / sankarapandian

SELECT SUM(case when col1='a' then 1 else 0 end) a_count,
SUM(case when col1='b' then 1 else 0 end)
b_count,
sum(case when col1!='a' and col1!='b' then 1
else 0 end)other_count
FROM t1

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which column of the user triggers data dictionary view displays the database event that will fire the trigger?

595


What are the indexing methods?

573


What is a temporal table?

495


What is pl sql code?

589


How do you go back in sql?

533






ERROR:Insert or update on table"accnt" violates foreign key constraints "acct_to_curr_symbol" DETAILS:KEY(accnt_curr_id)(-2)is not present in the table "curr_symbol" ......solve The Problem..

2006


What are different categories of sql commands?

632


how to get a list of all tables in a database? : Sql dba

513


Determine if oracle date is on a weekend?

556


Can two tables have same primary key?

531


What is program debugging?

563


What is the difference between left join and right join?

502


What is foreign key and example?

516


What is a design view?

520


How many triggers can be applied to a table?

600