I am trying to create a query where the user can select over 3 different filters : postal code, municipalities and departments.
The query should return the records where one, two or all of them are chosen for a specific year chosen
The SQL query is as :
select * from db.table
where year = 2021
and (
postal_code =22160
or
municipality = 'Ploumagoar'
or
department = 'Ain'
)
I've tried unsucessfully to do it in metabase using following code:
select * from db.table
where {{year}}
and (
{{postal_code}}
or
{{municipality }}
or
{{department }}
)
The 3 last fields - postal code, municipalities and departments - are not mandatory and should add up as OR conditions.
I've also tried to include the "[[ ]]" conditional formatting but it did not end up as expected.
Can you guide me in order to achieve this goal?
In the end, due to the field type and some mysterious issues, I had to tweak the code even more!
I am ending up with :
select * from datagouvimmo.foncier where
{{transactionyear}}
AND (
(
coalesce([[{{Commune}},]] true)
AND
coalesce([[{{Departement}},]] true)
)
[[OR {{Commune}}]]
[[OR {{Departement}}]]
)
Something that you ,@flamber, mention right here.
So once again: Thank you!