Sum values of one measurement by tag; mean over interval

Setup:

InfluxDB: v1.3.1
Grafana: v4.4.2

My InfluxDB measurement is laid out as follows:

time | value | tags
--------------------------------------
a    | 2     | type=type_a,host=host_a
a    | 4     | type=type_a,host=host_b
a    | 6     | type=type_b,host=host_c
b    | 3     | type=type_a,host=host_a
b    | 4     | type=type_a,host=host_b
b    | 5     | type=type_b,host=host_c

Now i query the sum of the value grouped by type:

SELECT sum("value") FROM "$retention"."$measurement" WHERE "type" =~ /^$type$/ AND $timeFilter GROUP BY time($__interval), "type" fill(null)

And while this query works, it has one major downside: The result of the query depends on the interval at which the data was inserted and the interval which is queried by $__interval: A query interval of three times the insertion interval would simply result in a tripling of the actual value, due to the sum aggregation.

Now i could just go ahead and lock both, the insertion and query interval for that value. But to keep things flexible i would rather not have to query intervals of 10s when viewing an entire year.

How can i write a query, that sum()s the values of the individual points in time and then aggregates the data over the time period using some other aggregation function, e.g. mean()?

I still need help with this :confused: