[SOLVED] How to write a query with multiple filter?

Hi guys!
I just want to know how to write a query using a field filter, wich will have a multiselect option

I already tried:
" le.description in {{evento}} "
" le.description = {{evento}} "
" and {{evento}} "

Filter Description, type category

My query
image

select d.name, EXTRACT(hour FROM sum(enddatetime - startdatetime)) as sumTime
from events e
inner join eventsdashboard le on le.eventtypeid = e.eventtypeid
inner join driver d on d.driverid = e.driverid
where eventcategory = ‘“Detail”’
and d.employeenumber is not null
and {{evento}} --THATS MY PROBLEM
[[ and cast(e.startdatetime as date) between {{datainicio}} and {{datafim}} ]]
group by d.name
having EXTRACT(hour FROM sum(enddatetime - startdatetime)) > 0
order by 2 desc

Version of my Metabase
“metabase-info”: {
“databases”: [
“postgres”
],
“hosting-env”: “unknown”,
“application-database”: “postgres”,
“run-mode”: “prod”,
“version”: {
“date”: “2019-12-19”,
“tag”: “v0.34.0”,
“branch”: “release-0.34.x”,
“hash”: “1335215”
},
“settings”: {
“report-timezone”: “America/Sao_Paulo”
}
}

Hi Nathalia!

If the field you’re working with is a category-type field, you should be able to configure the variable type as a “Field Filter”. I’ve included a few screenshots below of a configuration that works with the Sample Data. What error are you getting with the query where you have and {{evento}}? Can you include a screenshot of the variable config page as well?

My query:

SELECT * FROM products
WHERE rating < 5 AND {{ean}}

Screenshot of select widget:

Screenshot of variable config:

Let me know if that helps,

Damon

@dacort
Thank you for answer me, I do the field filter just like you said

But I think the problem it is the join that I made with tables. And I’ve got error only when I choose a option in the filter, when I dont choose anything it is work fine

Dont choose any option:

But I try a lot of things and I’ll show you

Using “and le.eventtypeid in {{evento}}” and “and le.eventtypeid = {{evento}}” (with ‘le’ as alias)

Using “and {{evento}}

Not using alias in any table “and {{evento}}

Using the select as a subselect and using the filter “and {{evento}}

This query have results, if I search for this information I get results

I don’t know what to do anymore, I dont want to write a query for each option :frowning:

About my database model

Description is a name of entity and EventTypeId is a Key of entity for my EventsDashboard table

Events Dashboard table

Event table

I don’t know what happened, but today when I came to work and try filters work again, they just work!

The sintax it works its the one with subselect
" and e.eventtypeid in (select eventtypeid from eventsdashboard where {{evento}}) "

Thank you guys anyway.

OK, glad you got it working!