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

What is difference between my sql and sql?

1077


Mention what is the function that is used to transfer a pl/sql table log to a database table?

995


what is bcp? When is it used?

1115


Can you join views in sql?

960


What is trigger in flip flop?

1007


What sql does db2 use?

983


Why is nosql good?

1029


How to change a value of the field ‘salary’ as 7500 for an employee_name ‘john’ in a table employee_details?

1439


What is the unique index?

1055


Can we debug stored procedure?

1031


how to check server status with 'mysqladmin'? : Sql dba

1078


What is function and procedure in pl sql?

1048


How many clustered indexes can be created on a table?

1076


how can I make a script that can be bi-language (supports english, german)? : Sql dba

1015


Define concurrency control. : Transact sql

1193