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

Is not equal in sql?

557


What sql does db2 use?

533


What is an emotional trigger?

508


What is relationship? How many types of relationship are there?

580


What are triggers in sql?

574






How to call shell script from pl sql procedure?

615


i have a column which may contain this kind of value: 123*67_80,12*8889_5,34*8_874 ,12*7_7 (can contain space before a comma, and this string length can be anything) now i want to split this value into two column like: column1: 123*67,12*8889,34*8,12*7 column2: 80,5,874,7 use function for this

1049


What is the primary key?

526


Is it important to partition hard disk?

524


Explain constraints in sql?

561


How do you write a complex sql query?

573


How do I find duplicates in a single column in sql?

524


Can you join a table to itself?

530


What action do you have to perform before retrieving data from the next result set of a stored procedure ?

2078


How do you optimize a query?

524