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 / vivek nagarajan
SELECT SUM(DECODE(txt,'a',1)) a_count,
SUM(DECODE(txt,'b',1)) b_count,
SUM(DECODE(txt,'a',0,'b',0,1)) others_count
FROM t1;
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
What does data normalization mean?
What is the best free sql database?
Does mysql_real_escape_string prevent sql injection?
name 3 ways to get an accurate count of the number of records in a table? : Sql dba
What is multiple columns?
What is relationship? How many types of relationship are there?
How to add new employee details in an employee_details table with the following details
How do I view stored procedures?
Why is sharding used?
Can a procedure in a package be overloaded?
What is rownum?
What is the difference between sum and count in sql?
What does where 1 1 mean in sql?
What is union?
How do you run a query?