This is a confusing question to ask, so I think it is best to just show an example of what I need. I have a data table that looks like Table A below. It is documenting the classes that students take, so there is a column for the class subject and a column for the student's name. What I need is a table that lists every combination of 2 subjects and the number of students in each combination, like Table B. (i.e. John is the only student in both History and Spanish, John and Sam are both in History and Math etc.) I can get the subject combinations with a cross join, but I don't know how to get the number of students in each combination.
Table A :
| class | name |
| --------- | ---- |
| Spanish | John |
| History | Sam |
| Math | Sam |
| History | John |
| Math | John |
| Spanish | Mark |
Table B:
|class1 | class2 | number of students |
|--------|---------|--------------------|
|Spanish | History | 1 |
|History | Math | 2 |
|Spanish | Math | 1 |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…