Constant Variables

I need to set constant variables in the SQL editor.
For example, I want to create a variable X that runs a query:
SET @X := SELECT AVG(Y) FROM TABLE.
Then, I want to use that variable in the next line:
SELECT * FROM TABLE2 WHERE attribute1 = @X

How can I do this?

Thanks!

Hi @ymoondhra
I don’t know which database you’re querying, but Metabase doesn’t handle multi-statements.
You can however use sub-query instead:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#using-an-existing-question-as-a-sub-query

1 Like