Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...



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








Answers were Sorted based on User's Feedback



Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / vinu

select decode (col1,'a','a','b','b','others') col1,count(col1) from T1 group by decode (col1,'a','a','b','b','others')

Is This Answer Correct ?    9 Yes 2 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / manas

select col1,count(*)cnt from T1 group by col1

Is This Answer Correct ?    8 Yes 2 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / vikneswaran

select decode(col1,'a','a','b','b','Other') "col1",count
(col1) "countval"
from col group by decode(col1,'a','a','b','b','Other');

Is This Answer Correct ?    1 Yes 0 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / rakesh prasad

select name ,count(name)as cnt from (
select case when ((name ='a') or (name = 'b') )then name
else
'others' end as 'name' from tbl_count ) as temp group by
name

Is This Answer Correct ?    1 Yes 0 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / sandhya

SELECT col1, count(*) cnt
FROM T1
GROUP BY col1
ODER BY col1

Is This Answer Correct ?    2 Yes 1 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / 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

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / kumarvijay

select decode(dept_id,1,1,2,2,0) "cnt" ,count(decode
(dept_id,1,1,2,2,0))
from deps group by decode(dept_id,1,1,2,2,0);

Is This Answer Correct ?    0 Yes 0 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / 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

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / vikneswaran

select decode(col1,'a','a','b','b','Other') "col1",count
(col1) "countval"
from col group by col1;

Is This Answer Correct ?    0 Yes 2 No

Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s ..

Answer / purushotham

SELECT PROD_CODE ,COUNT(1) FROM TFT_P_PROD WHERE
BRCH_CODE='784'
GROUP BY PROD_CODE;

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More SQL PLSQL Interview Questions

What is pseudo column ?

6 Answers   ABB,


What is int identity in sql?

0 Answers  


What is varchar used for?

0 Answers  


How to call shell script from pl sql procedure?

0 Answers  


What is cursor in pl sql?

0 Answers  


Define union, minus, union all, intersect ?

0 Answers  


Can we use rowid as primary key?

0 Answers  


Where is all the data on the internet stored?

0 Answers  


What is application trigger?

0 Answers  


Explain the purpose of %type and %rowtype data types with the example?

0 Answers  


Is oracel sql developer written in java?

0 Answers  


Hi All, I am new to both this blog and technology. I was able to see a response for one of the questions on triggers as below. I would like to know why are we using " if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then" instead, can't we use " if sysdate = 'sunday' then". I can understand the use of "rtrim", but dont know y v r using to_char. I have seen this in many cases but did not get a convincible explaination. Please help me with this and do excuse if this question sounds silly. Thanks in advance...... create or replace trigger trg_sun before insert on <table name> begin if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then raise_application_error(-20345,'no transaction in sunday'); end if; end trg_sun;

2 Answers  


Categories