Question : Counting the number of time an item occurs with another event

Hello,

I have the following table and I want to create a query that will display the number of times each InvestNum appears with each other InvestNum for the same EventNum.  For example, I want to display that A is in the same eventnumber as B three times and so forth for each Invest number.  I think that I might need a cross tab query but am not sure.
I would appreciate any help.  Thanks.


EventNum      InvestNum
1                         A
1                         F
1                         B
1                         C
1                         G
2                         A
2                         c
2                         D
2                         B
2                         F
3                         A
3                         E
3                         C
3                         B
3                         D

Answer : Counting the number of time an item occurs with another event

I am not sure if I understood your requirements. Look at the query below.
Is this what you need? For your example of data it returns following counts:

A      B      3
A      C      3
A      D      2
A      E      1
A      F      2
A      G      1
B      C      3
B      D      2
B      E      1
B      F      2
B      G      1
C      D      2
C      E      1
C      F      2
C      G      1
D      E      1
D      F      1
F      G      1
1:
2:
3:
4:
SELECT t1.InvestNum, t2.InvestNum, count(*)
FROM Table2 t1 INNER JOIN Table2 t2 ON ( t1.EventNum = t2.EventNum)
WHERE t1.InvestNum < t2.InvestNum 
group by t1.InvestNum, t2.InvestNum;
Random Solutions  
 
programming4us programming4us