0

I have a table with a composite key (a,b) wherein I want to return the first key and the count of the second key that have the exact same set. For example if we have:

 a | b
-------
01 | 2
01 | 3
02 | 1
02 | 2
02 | 3
03 | 2
04 | 2
04 | 3

Since 01 and 04 have the same second column (2,3) and the others have none we get:

01 | 1
02 | 0
03 | 0
04 | 1 

This should apply to any set of composite keys (a,b) and not its not just inclusion but equality we're looking for.

2
  • which database?
    – eshirvana
    Commented Apr 14, 2021 at 23:08
  • Doesn't really matter, it's a question from a textbook where they use basic sql. Commented Apr 15, 2021 at 11:44

0

Browse other questions tagged or ask your own question.