Math operations between tags (same field and measurement)

#1

So what I’m looking for is to do math operation (specifically subtraction in this case) between value::field where domain = D1 and where domain = D2.

This is my data

time                 GRP_ID           MCCMNC domain host      value
----                 ------           ------ ------ ----      -----
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D1     host1     900540
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D1     host2     900540
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D1     host6     900540
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D2     host7     900533
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D2     host8     900533
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D2     host9     900533
2018-08-13T12:10:00Z NON-DEFLTCELLGRP 310410 D2     host10    900533

So essentially this…but of course this doesn’t work:

(SELECT max(value) AS "MAX_OF_D1" from "glsDB_CTS" WHERE "MCCMNC" = '310410' AND "GRP_ID" = 'NON-DEFLTCELLGRP' AND "domain" = 'D1' group by time(5m)) - 
(SELECT max(value) AS "MAX_OF_D2" from "glsDB_CTS" WHERE "MCCMNC" = '310410' AND "GRP_ID" = 'NON-DEFLTCELLGRP' AND "domain" = 'D2' group by time(5m))

…and the result would be 7 (because 900540 - 900533)

time                 value
----                 ------
2018-08-13T12:10:08Z      7