Below is the INPUT Table having student and his/her two interests of learning different subjects.
Student | Int1 | Int2 |
---|---|---|
1 | DS | Networks |
2 | OS | DS |
3 | DS | OS |
4 | Networks | DB |
5 | OS | Networks |
6 | DB | DS |
7 | Networks | OS |
8 | DB | OS |
Need to find domain of interest and number of students interested in it.
Output Should be
Interest | Total Students |
---|---|
DS | 4 |
OS | 5 |
DB | 3 |
Networks | 4 |
2
Answers
First I join the 2 result in a temp table and count by the temp table.
You can query data from the two columns,then using
UNION ALL
to put them together,finally usingGROUP BY
to statistics dataDB Fiddle Demo
Test result