Connecting Tech Pros Worldwide Forums | Help | Site Map

Count of table column

Newbie
 
Join Date: Aug 2006
Posts: 8
#1: Jan 11 '08
Hi,
i have a table xx with column flg.

it has values like

flg
----
T
G
T
T
G
G
G
G

I want to write a query that would retrieve
count(flg) where flg='G'
and count(flg) where flg='T'
in a single line query.

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Jan 11 '08

re: Count of table column


Quote:

Originally Posted by hgriva

Hi,
i have a table xx with column flg.

it has values like

flg
----
T
G
T
T
G
G
G
G

I want to write a query that would retrieve
count(flg) where flg='G'
and count(flg) where flg='T'
in a single line query.

Expand|Select|Wrap|Line Numbers
  1. SELECT flg,COUNT(flg) from xx GROUP BY flg;
  2.  
  3. SELECT (SELECT COUNT(flg) from xx WHERE flg = 'G') G, (SELECT COUNT(flg) from xx WHERE flg = 'T') T FROM DUAL;
  4.  
  5.  
Newbie
 
Join Date: Aug 2006
Posts: 8
#3: Jan 11 '08

re: Count of table column


Quote:

Originally Posted by amitpatel66

Expand|Select|Wrap|Line Numbers
  1. SELECT flg,COUNT(flg) from xx GROUP BY flg;
  2.  
  3. SELECT (SELECT COUNT(flg) from xx WHERE flg = 'G') G, (SELECT COUNT(flg) from xx WHERE flg = 'T') T FROM DUAL;
  4.  
  5.  

Hi,
Thanks for your reply.
I need one more clarification.

if want count of flg where flg='G' and count of flg <>'G'
how would i get it
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#4: Jan 11 '08

re: Count of table column


Quote:

Originally Posted by hgriva

Hi,
Thanks for your reply.
I need one more clarification.

if want count of flg where flg='G' and count of flg <>'G'
how would i get it

Also try to use DECODE for the purpose.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#5: Jan 11 '08

re: Count of table column


Quote:

Originally Posted by hgriva

Hi,
Thanks for your reply.
I need one more clarification.

if want count of flg where flg='G' and count of flg <>'G'
how would i get it

Give a try to find a count for flg <> G using the ideas from the above post. Post back in case of any issues you face!!
Newbie
 
Join Date: Aug 2006
Posts: 8
#6: Jan 11 '08

re: Count of table column


Thanks.I got the answer
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#7: Jan 11 '08

re: Count of table column


Quote:

Originally Posted by hgriva

Thanks.I got the answer

We appreciate that!!...
Reply