r/ProgrammerHumor • • Apr 12 '19

It do be like that sometimes

Post image
16.7k Upvotes

365 comments sorted by

View all comments

Show parent comments

1

u/jj20051 Apr 12 '19

Link lol

1

u/Dimbreath Apr 12 '19

1

u/jj20051 Apr 12 '19 edited Apr 12 '19

Dumb question, but have you thought about a sum function query?

SELECT
    *
FROM (
    SELECT
        *,
        ((character_1 IN ('cidd', 'tenebria')) + (character_2 IN ('cidd', 'tenebria')) + (character_3 IN ('cidd', 'tenebria')) + (character_4 IN ('cidd', 'tenebria'))) as "matches"
    FROM
        campingcombinations
   HAVING matches > 1
) a
ORDER BY
    total_morale DESC

You might need an index on all 4 of the character columns.

To the SQL purists out there: Yeah I know I can do this without having.