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
Why we use triggers in mysql?
Explain the the delete statements in sql?
How to revise and re-run the last sql command?
what is error ora-03113: end-of-file on communication channel?
What is difference between stored procedure and trigger?
Define commit, rollback and savepoint?
what are date and time intervals? : Sql dba
What is native sql query?
Why are cursors used?
Can we join more than 2 tables in sql?
Give the order of sql select?
How many sectors are in a partition?
Does pl/sql support create command?
What are analytic functions in sql?
what is a database lock ? : Sql dba