Let’s say I have a table for showing data in the frontend, and the user can select all kinds of filters based on the columns. For text columns they can have certain text filters such as ‘starts with’, ‘contains’, ‘equals’, ‘is not equal to’, etc.
For columns with integers it would be stuff like ‘equals’, ‘greater than’, ‘less than’, ‘is not empty’, ‘is empty’.
For percentage columns the same etc etc.
How would one structure this, in broad terms, in the backend to recognize all these filters and place them in a query at the right place. So which filters would be a WHERE, which filters HAVING? Which filters go inside a join, which filters go outside a join or subquery?
And if certain columns show an average, how would you structure this so that certain filters get applied before or after an AVG function? If I want to see only AVG rows with a value above 20, OR I want to see AVG rows that are calculated from values above 20, both should be possible. Same with COUNT or SUM.
I’m struggling to come up with a coherent system that doesn’t become incredibly confusing and complex. How do other companies do this? Is there maybe a framework that has all this built in? I’m just using Symfony and MySQL.