Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How to read/write files from pl/sql?

1023


Define a temp table?

1004


How do I view tables in sql developer?

925


What is the maximum rows in csv?

911


what is clause? : Sql dba

1052


How can you select unique records from a table?

1053


List the various privileges that a user can grant to another user?

1033


What is attribute indicator in pl sql?

1001


How do I count rows in sql?

982


How can we optimize a sql query?

1030


how can we transpose a table using sql (changing rows to column or vice-versa) ? : Sql dba

934


What are different sql data types?

1016


what is the difference between cluster and non cluster index? : Sql dba

1007


Can we have two clustered index on a table?

1011


Can you sum a count in sql?

985