What exactly are you trying to achieve here as an end result and why are you using SUM? What is f_good, f_bad and f_ugly? Without context, specific details and expressions it's difficult to give relevant advice. Presumably you are trying to group data in a player report by certain board textures? Fo...