Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am using vb.net with visual studio 2005 and sqlserver 2000
I have a grid view named as gb1
WHICH HAS FOUR COLOUMNS A,B,C,D
and has the value like

HTML
A        B       C       D
1.0	2.0		1.0
2.0	1.0		3.0
-		2.0	


I WANT TO FIND A SUMMARY

LIKE

1.0 OCCURS =3 TIMES
2.0 OCCURS =3 TIMES
3.0 OCCURS =1 TIMES


i don't find the logic of this summary .
Please Help me regarding this condition.
Posted
Updated 19-Feb-13 21:15pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Feb-13 1:09am    
Get summary from SQL, not from control.
—SA
ankur789 20-Feb-13 1:11am    
sir then what query can i use .
i am using count with select but not find such a result i wanr
Sandeep Mewara 20-Feb-13 2:32am    
You need to tryout the query by yourself first.
[no name] 20-Feb-13 2:05am    
Do you want summary for row wise or column wise ?
ankur789 20-Feb-13 3:17am    
complete summary sir
if possible then coloumn wise

1 solution

this way...
SQL
select val,count(*) as Occurance from
(
    select a as Val from tblnm   _
    union all                     |
    select b from tblnm           |
    union all                      > this will get col a,b,c,d & then using union all merge all cols
    select c from tblnm           |
    union all                     |
    select d from tblnm          _|
) as t
group by val --here it grouped by val 

Happy Coding!
:)
 
Share this answer
 
v5
Comments
ankur789 20-Feb-13 3:14am    
mam here is a problem that i m not doing the selection on the basis of first coloumn let us consider the condition
a b c d
1.0 1.0
now the answer comes as 1.0 occurs 2 times but the query will not give right answer
Aarti Meswania 20-Feb-13 3:18am    
check it it's working properly
Aarti Meswania 20-Feb-13 3:19am    
see this example
with a as
(
select 10 as a, 10 as b, 1 as c union all
select 2 as a, 10 as b, 3 as c union all
select 1 as a, 3 as b, 2 as c
)
select count(*),a from
(
select a from a
union all
select b from a
union all
select c from a
) as t
group by a
ankur789 20-Feb-13 3:26am    
thanks ma'am ,
But mam one problem is also here.
tell me how this query works means how this query fetch the values
Aarti Meswania 20-Feb-13 3:39am    
see solution
I have describe there
see set of 4 select Queries with union all copy that and execute you will see all 4 column values are gather now in a single column 'val'

and then I have grouped that val column and count how many time particular val occur

Hope you understand how it worked :)

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