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 difference between my sql and sql?
Mention what is the function that is used to transfer a pl/sql table log to a database table?
what is bcp? When is it used?
Can you join views in sql?
What is trigger in flip flop?
What sql does db2 use?
Why is nosql good?
How to change a value of the field ‘salary’ as 7500 for an employee_name ‘john’ in a table employee_details?
What is the unique index?
Can we debug stored procedure?
how to check server status with 'mysqladmin'? : Sql dba
What is function and procedure in pl sql?
How many clustered indexes can be created on a table?
how can I make a script that can be bi-language (supports english, german)? : Sql dba
Define concurrency control. : Transact sql