Reputation: 81
I am performing a select query to select time-series values. I select the column with the timestamp and the column with a measured value from two sub-queries that contain the relevant data.
SELECT
t1.measured_value as value,
t2.time
FROM (
SELECT measured_value , ROW_NUMBER() OVER () AS rownum
FROM time_series_data
) t1
JOIN (
SELECT time, ROW_NUMBER() OVER () AS rownum
FROM timestamp_data
) t2 ON t1.rownum = t2.rownum
Instead of having the alias as name "value", I want an alias based on an single value that can be selected from another table. Naively it would look something like this:
t1.measured_value as (select real_alias_name from names where id = someID)
Which obviously doesn't work. Is there a way to achieve this or do I need a completely different approach?
I have a second table which contains the alias name for my measured time series. I cannot use a static alias name, since the alias should be based on values from a table. I only need it as alias name because I am using Grafana. So if anybody has a suggestion on how to do this in Grafana directly, it would also help. But I cant seem to find a way to select column values from tables for the name attribute there.
Upvotes: 0
Views: 973
Reputation: 8915
Aliases have to be statically defined, but you could select a 3rd column containing the name coming from your second table (although I don't think it would fix your grafana problem).
Upvotes: 0