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
What is the difference between sql and t sql?
when is the use of update_statistics command? : Sql dba
What is cross join example?
What can sql server reporting services do?
Why are cursors used?
what tools available for managing mysql server? : Sql dba
What is trigger in sql and its types?
What is sqlcontext?
Why do we use function in pl sql?
How many databases can sql express handle?
what are different types of collation sensitivity? : Sql dba
Is sql pronounced sequel or sql?
What is the purpose of primary key?
What are the different types of dbms?
What is a column in a table?