Home » SQL & PL/SQL » SQL & PL/SQL » COUNT of distinct values in 2 columns
COUNT of distinct values in 2 columns [message #278524] Sun, 04 November 2007 22:01 Go to next message
ram_ocp
Messages: 49
Registered: December 2005
Location: Karnataka
Member
Hi,

I am stuck with something which i guess is very easy.Could you plese let me know

I want to count distinct values of 2 columns in a oracle table
The result should be like

Column 1 Column 2 Count (*)
a1 b1 5
a1 b2 3
a2 b1 4

Please help me with the query,i am not able to use the count function for 2 columns


Ram
Re: COUNT of distinct values in 2 columns [message #278525 is a reply to message #278524] Sun, 04 November 2007 22:06 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
>i am not able to use the count function for 2 columns
Show what SQL you've tried using CUT & PASTE along with <code tags> & explain why it does meet the requirement(s).
Re: COUNT of distinct values in 2 columns [message #278529 is a reply to message #278524] Sun, 04 November 2007 22:24 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
hi,

You can through the group by like below

select col1,col2 from table1 group by col1,col2;

Thanks

Mano

Re: COUNT of distinct values in 2 columns [message #278786 is a reply to message #278524] Mon, 05 November 2007 12:05 Go to previous message
Bill B
Messages: 1484
Registered: December 2004
Senior Member
If you mean a seperate count for each column then

select count(distinct col1),count(distinct col2)
from my_table;
Previous Topic: simple query
Next Topic: data unload from a table with daily partition
Goto Forum:
  


Current Time: Thu Dec 08 08:35:22 CST 2016

Total time taken to generate the page: 0.29440 seconds