Query and subquery filter other values (other entity_id)

Hi all,
I’m trying to create a query to summarize energy consuption by day.
The query works fine:

SELECT mean(“mean”)*24 FROM (SELECT mean(“value”) FROM “KWh” WHERE (“entity_id” = ‘pdc_pt_in_w’) AND $timeFilter GROUP BY time(5s) fill(linear) tz(‘Europe/Rome’) ) GROUP BY time(1d) fill(0) tz(‘Europe/Rome’)

I need to consider the results only where the entity id like “acs_prod” is equal to “1”.
How can achive this goal?

Best regards

Hi, the condition for the query is if SELECT mean(“value”) FROM “states” WHERE (“entity_id” = “pdc_pt_acs_prod” AND value = “1”)

I want to fetch the KWh only when pcd_pt_acs_prod state is 1.

It’s possible?