SQL syntax to show one variable Y according to another one X which is not the time

Hi,

I am a new user of Grafana, I am not yet very cumfortable with query editor. That is why, i use SQL editor.

My first request works well, and with the gauge I have what I want :

SELECT
submitdate AS “time”,
150703X172X2661 AS metric,
avg(150703X172X2661) AS “Moyenne”
FROM ask_survey_150703
WHERE
$__timeFilter(submitdate)
ORDER BY submitdate

My second request doesn’t work, I would like to bypass the time component to have a “picture” of the average of this variable 150703X172X2661 (AXIS Y) according to this variable (AXIS X) attribute_4 (token is the link between both tables), on a Graph :

SELECT Avg(ask_survey_150703.150703X172X2661), ask_tokens_150703.attribute_4
FROM ask_survey_150703 INNER JOIN ask_tokens_150703 ON ask_survey_150703.token = ask_tokens_150703.token
GROUP BY ask_tokens_150703.attribute_4
HAVING ask_tokens_150703.attribute_4<>""

With this error message, that I understand : Found no column named time or time_sec
So, my third request :

SELECT submitdate AS “time”
Avg(ask_survey_150703.150703X172X2661), ask_tokens_150703.attribute_4
FROM ask_survey_150703 INNER JOIN ask_tokens_150703 ON ask_survey_150703.token = ask_tokens_150703.token
GROUP BY ask_tokens_150703.attribute_4
HAVING ask_tokens_150703.attribute_4<>""

With this error message, that I don’t understand : Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘Avg(ask_survey_150703.150703X172X2661), ask_tokens_150703.attribute_4
FROM ask_’ at line 2

So my last request : the community :grin:

Thanks for your help,
Regards,
Christophe.

You are missing a comma after “time”

SELECT submitdate AS “time”,
Avg(ask_survey_150703.150703X172X2661),
ask_tokens_150703.attribute_4
FROM ask_survey_150703
INNER JOIN ask_tokens_150703
ON ask_survey_150703.token = ask_tokens_150703.token
GROUP BY ask_tokens_150703.attribute_4
HAVING ask_tokens_150703.attribute_4<>""

Sorry for my mistake. It is a problem of copy-past. In the code, the coma is not missing and I confirm it doesn’t work :frowning:

I did not find the documentation about the syntax rules. For instance, i succed the following syntax but I do not know how and why :slight_smile:

SELECT
__timeGroupAlias(submitdate,__interval),
avg(150703X172X2661)
FROM ask_survey_150703
WHERE
__timeFilter(submitdate) GROUP BY submitdate ORDER BY __timeGroup(submitdate,$__interval)

Regards,
Christophe.