Skip to content
Advertisement

Optimising query with multiple selects as columns

I have a query I made:

The results table has 25000 entries and it takes around 7 seconds to do this query, which is far too long. The query is incredibly inefficient as each column I’m creating is searching again on the same table but with different conditions.

I tried indexing the columns of interest in my where clause. This knocks off a couple of seconds. But it’s still too slow.

What is the best approach to handle this kind of query?

I’m using MariaDB 10.2

Advertisement

Answer

Unpivot the data then aggregation:

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