MYSQL alias it's possible?

Hi,

i would like to know, if it’s possible to give an alias on my QUERY ?
i have two query with the same select but different where. And i would like to give an different name to my QUERY.

i’ve saw it’s that possible with datasource like ZABBIX or other but i don’t find the field when i choose datasource MYSQL

can you help me please ?

Hi,

You can add multiple queries. Click on the button Add Query.

Marcus

yes i used already, but in my legend this is the same name, so if i want change the color for one it’s not possible, grafana don’t understand and the color change for both.

the only difference only my two query it’s with the WHERE of my MSQL request, the select is the same.

this for that i would like to add an alias and change the name of my legend. i saw it’s what possible with other datasource but i don’t know if it’s available with MYSQL datasource…

Select ‘Something’ as metric will render something as label.

look :slight_smile:

1st query :
SELECT
UNIX_TIMESTAMP((date(climbing_time))) as time_sec,
count(c.id) as value,
i.type as metric
FROM YY i
INNER join XX c ON (i.id = c.incident_id)
WHERE
DAYOFWEEK( climbing_time ) BETWEEN 2 AND 6
AND MONTH( climbing_time ) = IF( MONTH( CURDATE() ) = 1, 12, MONTH( CURDATE() ) - 1 )
AND YEAR( climbing_time ) = IF( MONTH( CURDATE() ) = 1, YEAR( CURDATE() ) - 1, YEAR( CURDATE() ) )
AND (time(c.climbing_time) between ‘07:00’ and ‘18:59’)
GROUP BY time_sec

2nd query :
SELECT
UNIX_TIMESTAMP((date(climbing_time))) as time_sec,
count(c.id) as value,
i.type as metric
FROM YY i
INNER join XX c ON (i.id = c.incident_id)
WHERE
DAYOFWEEK( climbing_time ) BETWEEN 2 AND 6
AND MONTH( climbing_time ) = IF( MONTH( CURDATE() ) = 1, 12, MONTH( CURDATE() ) - 1 )
AND YEAR( climbing_time ) = IF( MONTH( CURDATE() ) = 1, YEAR( CURDATE() ) - 1, YEAR( CURDATE() ) )
AND (time(c.climbing_time) between ‘19:00’ and ‘23:59’ OR (time(c.climbing_time) between ‘00:00’ AND ‘06:59’))
OR
DAYOFWEEK( climbing_time ) NOT BETWEEN 2 AND 6
AND MONTH( climbing_time ) = IF( MONTH( CURDATE() ) = 1, 12, MONTH( CURDATE() ) - 1 )
AND YEAR( climbing_time ) = IF( MONTH( CURDATE() ) = 1, YEAR( CURDATE() ) - 1, YEAR( CURDATE() ) )
GROUP BY time_sec

the difference between the both, it’s the WHERE but the select is the same…
i don’t know how to do for differentiate in my graph.

That looks correct besides that you probable want to group by both time_sec and metric (i.type). i.type should render as labels. Then also add a order by time_sec

@mefraimsson I have similar case, I want to show two different lines in same graph using MySql query, But I am getting single connected line

Visualization section:
stack -> enabled
Line->enabled
X-Axis mode->Time
Legend->total

First Query:
Select
UNIX_TIMESTAMP(created_ts) as time_sec,
sum(message_type in (‘A’, ‘B’, ‘C’, ‘D’, ‘E’)) as value,
date_format(created_ts,’%b-%y’) as metric
from
db.MessagePerformance
where
$__timeFilter(created_ts)
Group by
date_format(created_ts,’%b-%y’)
Order by
time_sec;

Second query:
Select
UNIX_TIMESTAMP(created_ts) as time_sec,
sum(message_type in (‘X’, ‘Y’, ‘Z’)) as value,
date_format(created_ts,’%b-%y’) as metric
from
db.MessagePerformance
where
$__timeFilter(created_ts)
Group by
date_format(created_ts,’%b-%y’) and time_sec
order by
time_sec;