Several curves on same graph. One curve for each variable value

Hello everyone!
I use mysql datasource. And I use template variable for dashboard.
How to display a curve for each variable value?
With only one Query in Metrics tab for graph.
I see an example. But it is for elasticsearch only.
How to make it work for mysql?

Thanks!