# Aggregate continuous queries for counters

**URL:** <https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228>\
**Category:** Systems\
**Tags:** influxdb, time\
**Created:** [November 28, 2017, 8:07am UTC](https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228 "2017-11-28T08:07:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![est](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/est/32/1896_2.png) [@est](https://community.influxdata.com/u/est)\
**Post date:** [November 28, 2017, 8:07am UTC](https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228/1 "2017-11-28T08:07:17Z")

</div>

Hi,

I have a measurement looks like this:

```
hits host
1 server_a
1 server_a
1 server_b

```

I want to aggregate it into per second like

```
hits host
2 server_a
1 server_b

```

WHat’s my best approach to do this?

Everytime I try SELECT COUNT(hits), host … GROUP BY influxdb says

```
ERR: error parsing query: mixing aggregate and non-aggregate queries is not supported
```

---

<div class="post-metadata">

**Author:** ![katy](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/katy/32/855_2.png) [@katy](https://community.influxdata.com/u/katy)\
**Post date:** [December 4, 2017, 8:04pm UTC](https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228/2 "2017-12-04T20:04:35Z")

</div>

The problem is that host (assuming host is a tag) can’t be used with an aggregate. In order preserve your tags and aggregate along the host dimension, have a `GROUP BY *`

```auto
SELECT count(hits) as hits 
FROM <measurement> 
WHERE <time condition> 
GROUP BY time(1s), * 

```

---

<div class="post-metadata">

**Author:** ![est](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/est/32/1896_2.png) [@est](https://community.influxdata.com/u/est)\
**Post date:** [December 7, 2017, 6:57am UTC](https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228/3 "2017-12-07T06:57:23Z")

</div>

Hello Katy,

Thanks for the reply, I am actually trying to create a CQ by downsampling `hits` fields by aggregate by every 1 seconds.

However, my main problem is that I lost all tags info like the `host` in the above example.

I am trying to get

```
SELECT COUNT(hits) as hits, host FROM ... GROUP BY time(1s), host

```

but it does not work.

Influxdb will result

> ERR: error parsing query: mixing aggregate and non-aggregate queries is not supported

---

<div class="post-metadata">

**Author:** ![est](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/est/32/1896_2.png) [@est](https://community.influxdata.com/u/est)\
**Post date:** [December 7, 2017, 7:02am UTC](https://community.influxdata.com/t/aggregate-continuous-queries-for-counters/3228/4 "2017-12-07T07:02:11Z")

</div>

OK now I get it, Influxdb will automatically add tags if `GROUP BY time(1s), *`. Case closed.
