Can I plot two or more device data into one graph via one querry?

Hello folks,

I am trying to visualize our test results. I would like to plot data from two (or potentially more) devices into one graph with one curve representing each device. The data comes from a test, is stored in a single Postgresql DB table and looks something like this:

Timestamp | Device | CPU_Load
01/19/2022 11:08:55 | Device 1 | 90
01/19/2022 11:08:56 | Device 1 | 85
01/19/2022 11:08:55 | Device 2 | 10.5
01/19/2022 11:08:56 | Device 2 | 10.5

The problem I am having is that the devices have the same timestamp meaning I have two values connected to one timestamp. Therefore, the resulting graph looks understandly like this:

However, I would like to have each device represented by one curve, so for example if I had two devices, I would have two curves.

I have looked into a simillar question (link here) and I have realized I could just simply create a new query for each device with a WHERE condition. However, for my purpose it would be highly impractical, because the number of devices we use for our test varies with time. Sometimes it can be 100 for example and writing 100 querries seems to be too much.

Is there any possbility to “tell” Grafana to split the data point into two curves with a single query?

Grafana version:

Postgresql v11

check out this graphite query: it is a single query but returns four distinct time series. View it with Table view and you will see that the dataframes are arranged into four distinct tables. This is basically the schema you would need to return from postgres for this to work: