views:

68

answers:

2

here is the whole picture. There is a table (table programparticipants) that stores all participants of all programs, there is another table (table programs) that stores all the programs. What I need to accomplish is the following:

  1. Acquire the programs where a user has attended more than one program (done)
  2. Acquire the other programs (from step 1) that a user attended based one one program
  3. Acquire the count of occurences that of two programs being attended by users.

Example table (programparticipants)

UserID     Program
1          2
1          3
2          2
2          4
2          5
3          1
3          2
3          5
3          6
3          7
4          5  
4          6
4          7
5          4
5          5
5          6
5          7

Example output

  • prog 2 - ASSOCIATED PROGRAMS(3)
  • prog 2 - OCCURENCES (1)
  • prog 2 - ASSOCIATED PROGRAMS(4)
  • prog 2 - OCCURENCES (1)
  • prog 2 - ASSOCIATED PROGRAMS(6)
  • prog 2 - OCCURENCES (1)
  • prog 2 - ASSOCIATED PROGRAMS(7)
  • prog 2 - OCCURENCES (1)
  • prog 4 - ASSOCIATED PROGRAMS(2)
  • prog 4 - OCCURENCES (1)
  • prog 4 - ASSOCIATED PROGRAMS(5)
  • prog 4 - OCCURENCES (2)
  • prog 4 - ASSOCIATED PROGRAMS(6)
  • prog 4 - OCCURENCES (1)
  • prog 4 - ASSOCIATED PROGRAMS(7)
  • prog 4 - OCCURENCES (1)
  • prog 5 - ASSOCIATED PROGRAMS(4)
  • prog 5 - OCCURENCES (2)
  • prog 5 - ASSOCIATED PROGRAMS(6)
  • prog 5 - OCCURENCES (3)
  • prog 5 - ASSOCIATED PROGRAMS(7)
  • prog 5 - OCCURENCES (3)
  • prog 6 - ASSOCIATED PROGRAMS(2)
  • prog 6 - OCCURENCES (1)
  • prog 6 - ASSOCIATED PROGRAMS(5)
  • prog 6 - OCCURENCES (3)
  • prog 6 - ASSOCIATED PROGRAMS(7)
  • prog 6 - OCCURENCES (3)
  • prog 7 - ASSOCIATED PROGRAMS(2)
  • prog 7 - OCCURENCES (1)
  • prog 7 - ASSOCIATED PROGRAMS(4)
  • prog 7 - OCCURENCES (1)
  • prog 7 - ASSOCIATED PROGRAMS(5)
  • prog 7 - OCCURENCES (3)
  • prog 7 - ASSOCIATED PROGRAMS(6)
  • prog 7 - OCCURENCES (3)

This will be going into a datagrid displaying something like:

      prog 1     prog 2     prog 3     prog 4     prog 5     prog 6     prog 7
prog 1             
prog 2                        1          1                     1          7
prog 3             1
prog 4             1                                2          1          1
prog 5                                   2                     3          3
prog 6             1                                3                     3
prog 7             1                     1          3          3

If anymore explaination is needed please let me know.

I do have existing code if needed.

+1  A: 

What you are asking for is called a pivot table or crosstab report. How you implement it will depend on your RBDMS. Some databases such as Oracle have built in functionality to do this. In others such as MySQL you have to do a little more work.

Asaph
This is a MS SQL database. What I was actually planning on doing what acquiring the list of all programs where a user has attended more than one. Then take that list and perform a loop through each program and perform the queries and populate a datatable within C# to create it. Iknow it can be done I have seen it done this way, but all I need is the data and I can not for the life of me acquire the data I need, past step 1 above
mattgcon
A: 

LOL sorry everyone, I was actually acquiring the necessary data in the query, however I was taking into account that the queried program was returning itself as well. and I just have to add a counter to each program that is returned.

So I believe I can get it all to work now. Thank you though, and this site is AWESOME. I have had great help in the past week solve some issues that I have had

mattgcon