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
Which column of the user triggers data dictionary view displays the database event that will fire the trigger?
What are the indexing methods?
What is a temporal table?
What is pl sql code?
How do you go back in sql?
ERROR:Insert or update on table"accnt" violates foreign key constraints "acct_to_curr_symbol" DETAILS:KEY(accnt_curr_id)(-2)is not present in the table "curr_symbol" ......solve The Problem..
What are different categories of sql commands?
how to get a list of all tables in a database? : Sql dba
Determine if oracle date is on a weekend?
Can two tables have same primary key?
What is program debugging?
What is the difference between left join and right join?
What is foreign key and example?
What is a design view?
How many triggers can be applied to a table?