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
How to read/write files from pl/sql?
Define a temp table?
How do I view tables in sql developer?
What is the maximum rows in csv?
what is clause? : Sql dba
How can you select unique records from a table?
List the various privileges that a user can grant to another user?
What is attribute indicator in pl sql?
How do I count rows in sql?
How can we optimize a sql query?
how can we transpose a table using sql (changing rows to column or vice-versa) ? : Sql dba
What are different sql data types?
what is the difference between cluster and non cluster index? : Sql dba
Can we have two clustered index on a table?
Can you sum a count in sql?