Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my query i want to take the distinct count

Table :

Coloumn 1     Coloumn 2   Coloumn 3
   1             Y           3
   2             Y           3
   3             Y           3
   4             Y           4
   5             Y           4

here i want the count of coloumn 2 and 3.
i tried
SQL
select count (distInct Coloumn 2 ),count (distinct Coloumn 3 ) from table.

but the result was count ( Coloumn 2 ) = 1 and count ( Coloumn 3 ) = 2
but am expecting count ( Coloumn 2 ) = 2 and count ( Coloumn 3 ) = 2
how can i do this?
Any solution ?

[edit]Code block added[/edit]
Posted
Updated 12-Jun-13 2:17am
v6
Comments
Am Gayathri 12-Jun-13 5:34am    
Column 1 Column 2 Column 3
1 Y 3
2 Y 3
3 Y 3
4 Y 4
5 Y 4
Result i got
Count(Column 1) Count (Column 2)
1 2

Expected result
Count(Column 1) Count (Column 2)
2 2
gvprabu 12-Jun-13 5:41am    
Your Question is still not clear, explain more about your Problem. For column 2 Distinct values is 1 right (Y). then how u will expect 2?
Am Gayathri 12-Jun-13 5:48am    
Column 3 values are different..here i need to take the count based on column 3.
since for column 3 for value 3 total 3 records and for value 4 total two records so the total count of column 3 should be 2 and column 2 should be 2.
Sridhar Patnayak 12-Jun-13 8:24am    
How you are expecting the column 2 will get the count=2, because it has only one unique value. Your question is wrong.
Amey K Bhatkar 12-Jun-13 5:52am    
Use Dense_Rank

I guess its not possible since distinct will only consider unique values. Since in column 2 only Y is present it will give the count as 1.
 
Share this answer
 
Comments
Am Gayathri 12-Jun-13 5:40am    
:( what to do here?
Sridhar Patnayak 12-Jun-13 8:25am    
Arun. you are correct.
Am Gayathri 12-Jun-13 9:33am    
Solved..:)
Use :
SQL
SELECT  count(T.Coloumn2 ) Column2Count, count(T.Coloumn3 ) Column3Count
FROM (SELECT DISTINCT Coloumn2 ,Coloumn3  FROM table) T
.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900