Hi
I imported some data into a MySQL Database. I plot the data in a graph but for some reason it splits up the data into different colors, eventhough it shouldn’t. See picture below.
I would like that all entries with the same name are also in the same color.
Here my code:
SELECT
$__timeGroup(timestamp,$interval,NULL) as time_sec,
sum(Amount) as value,
Partname as metric
FROM
statistik
WHERE
$__timeFilter(timestamp)
GROUP BY 1
ORDER BY 1
What maybe is also good to know is that I did not import all the data at once. The changing color occurs when I add a new measurement over time. In the MySQL database all the partnames look the same to me.
So this means somewhere there has to be a difference in the names? I can not explain myself how this happened but probably reuploading everything at once properly would solve the issue.
But how would I group the entries? I tried the two following things but I could not get the right result:
GROUP BY SUBSTRING(Partname, 1, 7)
I found out that it must probably be because some of the entries have a space in the end of the string and the others not. So I though if I would just compare the first 7 letters I could come to the right result. It is grouping the entries now in only three categories, which is right, but all the entries are also grouped all at one timestep.
I got it working:
I should not do the grouping in the GROUP BY section but in the metrics section.
SELECT
$__timeGroup(timestamp,$interval,NULL) as time_sec,
sum(Amount) as value,
SUBSTRING(Partname, 1, 7) as metric
FROM
statistik
WHERE
$__timeFilter(timestamp)
GROUP BY 1
ORDER BY 1