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 user in sql?
Does sql use python?
What are the types of join and explain each?
explain normalization concept? : Sql dba
Explain ttitle and btitle.
What are the different dml commands in sql?
What is the benefit of foreign key?
What is difference sql and mysql?
Does varchar need length?
What is a data manipulation language?
What is basic structure of pl sql?
what is sql? : Sql dba
How do I run a script in sql developer?
How do sql triggers work?
what's the difference between a primary key and a unique key? : Sql dba