I have a table like this
gems
----------
id, color
1 , green
2 , green
3 , blue
4 , red
5 , red
6 , red
7 , rainbow <<<<< OMNI COLOR
8 , rainbow <<<<< OMNI COLOR
And I’m trying to get results like this
color count, each rainbow is added to each color
---------------
color , count
green , 4
blue , 3
red , 5
I’ve been trying various combinations of joins and group bys but i’m not sure how to approach this. In this example each normal color should only be counted once, but each rainbow gem needs to be counted multiple times, and in the real problem there are an X amount of distinct ‘colors’
Here is a fiddle to show the query working.