Skip to content
Advertisement

Count the number of appearances of char given a ID

I have to perform a query where I can count the number of distinct codes per Id.

The output should be something like:

Can you give me some advise on this?

Advertisement

Answer

If the codes are only to the provided ones, the following query can provide the desired result.

Note: as I can see from sample input data, code ‘I’ is found in all of Ids. Its count is zero for Id = 3 in the expected output (in the question).

Here is the correct output:

enter image description here

DB Fiddle

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement