Save sql query in table and add dinamically where clauses

Keywords: java sql teradata

Question: 

this is not exactly a code problem but I need some advice to know which would be the best way to achieve this.

I have an application where I have to save bit queries in a table from a database(yes, this is horrible, but that's a requirement). A user in a the frontend side does a selection of selectors and the data selected goes by json to a backend.

There in the backend I have a table which has the query statement saved in a column and depending on the selection of the user the WHERE clause will be formed.

Once I have that I execute the query and retrieve the data to be displayed in the front.

Suppose that the query is somethign like this:

Answers: