Multiple timeseries, pivot column

Grafana is able to produce graphs out of a single query with result set such as rows of times and value, in order to have another graph we can add a second query on the same graph like:

q1) SELECT time, value FROM test WHERE series_name = ‘A’;
q2) SELECT time, value FROM test WHERE series_name = ‘B’;

the issue is that in some cases we don’t know in advance the name of series and most of all how many series we have, the ideal would be to do:

SELECT time, series_name, value FROM test;

and then tell Graphan that series_name is the column it has to use for pivoting the values producing out of it multiple lines.