Construction of my first Continuous Queries

Hi there,

I am trying to make my first CQ, and I am a little stuck, I have been able to get data from a measurement that has several tags in it but I need it to be specific to the queries listed below and and then ultimately minus each other.

SELECT mean(“current_power_w”) AS “mean_current_power_w” FROM “homeassistant”.“autogen”.“watts” WHERE time > :dashboardTime: AND “entity_id”=‘power_ct1_40_540’ GROUP BY time(:interval:) FILL(none)

and

SELECT mean(“current_power_w”) AS “mean_current_power_w” FROM “homeassistant”.“autogen”.“watts” WHERE time > :dashboardTime: AND “entity_id”=‘power_ct2_40_539’ GROUP BY time(:interval:) FILL(none)

Here is one of my attempts that failed, I have just tried to get the data before adding the complication of math.

CREATE CONTINUOUS QUERY “cq_total_energy” ON “homeassistant”
BEGIN
SELECT last(“current_power_w, entity_id=power_ct1_40_540”)
AS “current_power_w”
INTO “Power”
FROM “homeassistant”.“autogen”.“watts”
GROUP BY time(30s)
END

Thanks in advanced

Duplicate: