MySQL query alias

Hi,

it would be great to get the possiblity to set an alias for querys when using MySQL as datasource similar as it is with influx. Some plugins make use of this (Bubble chart) and don’t work fully since this is missing.

Best regards
Alex

Can you explain a bit more? Do you mean the Alias by field in InfluxDB? If so, you can set anything as alias in MySQL very easily and use it with the Bubblechart:

I mean the alias by field:
image

as I understood the bubble chart can do grouping by this field. But maybe I am wrong?

If you look at my example above it is a working mysql query for the Bubblechart. The “metric” field is the same as the “ALIAS BY” in InfluxDB.

Here is the query, the “achar” field is used for the grouping:

SELECT
  UNIX_TIMESTAMP(atimestamp) as time_sec,
  aint as value,
  achar as metric
FROM testdata.mysql_types
WHERE $__timeFilter(atimestamp)
ORDER BY atimestamp ASC

EDIT: You can hardcode values as well:

'Keller' as metric

That I get and works but what I want is something like in the pictures at the plugin page:
image

Sounds like you want to group by something then? Have you tested a group by in your sql query?

@daniellee - Is it possible to have multiple metric fields in TimeSeries select SQL query like this?

SELECT
UNIX_TIMESTAMP(date) as time_sec,
amt as value,
server as metric,
org as metric
FROM trade
WHERE $__timeFilter(date)
ORDER BY date ASC

In the above SQL, we always get ‘org’ field in the series collection within chart plugin. It doesn’t fetch ‘server’ information from SQL database.

In other TSDBs, we can have multiple tags and can define custom alias pattern for tags, not sure how we can achieve similar behaviour within SQL query.

Bubble-chart plugin tries to group multiple series data at the client end on the basis of alias pattern and in case of SQL, we always get the single metric field as alias value.

@biobier - I am able to achieve grouping in Bubble-chart panel by the following expression. Give a try.

SELECT
UNIX_TIMESTAMP(date) as time_sec,
amt as value,
CONCAT(server, ‘,’, ‘org’) as metric
FROM trade
WHERE $__timeFilter(date)
ORDER BY date ASC

1 Like

Nice work! Wondering if this should be documented somewhere.

I will update readme.