title: clickhouse - how get count datetime per 1minute or 1day ,
body: <p>I have a table in <a href="https://clickhouse.yandex/" rel="noreferrer">Clickhouse</a>. for keep statistics and metrics.
  <br/>
  and structure is: </p>
  
  <pre><code>datetime|metric_name|metric_value
  </code></pre>
  
  <p>I want to keep statistics and limit number of accesses in 1 minute, 1 hour, 1 day and so on. So I need event counts in last minute, hour or day for every metric_name and I want to prepare statistics in a chart.
  <br/>
  I do not know how to make a query. I get the count of metrics statistics based on the exact for example 1 minute, 1 hour, 1 day and so on.</p>
  
  <p>I used to work on <a href="https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/" rel="noreferrer">inflxdb</a>:</p>
  
  <pre><code>SELECT SUM(value) FROM `TABLE` WHERE `metric_name`=`metric_value` AND time &gt;= now() - 1h GROUP BY time(5m) fill(0)
  </code></pre>
  
  <p>In fact, I want to get the number of each metric per 5 minutes in the previous 1 hour.</p>
  
  <p>I do not know how to use aggregations for this problem</p>