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
Is not equal in sql?
What sql does db2 use?
What is an emotional trigger?
What is relationship? How many types of relationship are there?
What are triggers in sql?
How to call shell script from pl sql procedure?
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
What is the primary key?
Is it important to partition hard disk?
Explain constraints in sql?
How do you write a complex sql query?
How do I find duplicates in a single column in sql?
Can you join a table to itself?
What action do you have to perform before retrieving data from the next result set of a stored procedure ?
How do you optimize a query?