How to group by week in MySQL? - $__timeGroup problem

I can’t use the $__timeGroup macro with MySQL database on Grafana table.

I would like to use it: http://docs.grafana.org/features/datasources/mysql/#time-series-queries

Example with $__timeGroup macro:

SELECT
  $__timeGroup(time_date_time,'5m') as time_sec,
  min(value_double) as value,
  metric_name as metric
FROM test_data
WHERE $__timeFilter(time_date_time)
GROUP BY 1, metric_name
ORDER BY 1

This is my original query:

SELECT 
UNIX_TIMESTAMP(day) as time_sec, SUM(cardinality) AS value, resource_id, 'CT' as metric
FROM 
stat_daily
WHERE
$__timeFilter(day) AND
type = "table" AND
resource_id IN ($forras)
group by UNIX_TIMESTAMP(day), metric

I would lik to try this macro:

SELECT 
$__timeGroup(day,'1w') as time_sec, SUM(cardinality) AS value, resource_id, 'CT' as metric
FROM 
stat_daily
WHERE
$__timeFilter(day) AND
type = "table" AND
resource_id IN ($forras)
group by 1, metric

I received an error message as:

Unknown macro __timeGroup

In inspector:

response:Object
results:Object
A:Object
error:"Unknown macro __timeGroup"
refId:"A"
meta:Object
series:null
tables:null
message:"Unknown macro __timeGroup"

How can I use it? What is the good syntax?

Thank you!

Which Grafana version are you using? MySQL $__timeGroup is not in the 4.6 branch so you need to use nightly build.

Oh, thank you! My version is v4.6.3 (commit: 7a06a47).