from query to graph

I am new in grafana, i want to enter an sql query (in the edit SQL section) and grafana automatically visualize the data or automatically fill the (FROM, SELECT, WHERE,…) section to visualize graphs.
in fact i have many .sql files containing long sql queries and i want to convert them to graphs
i will be very thankful for your help.

Create a graph panel of the type you require, go to the query editor and
toggle the edit mode so that you can see the raw SQL query, and simply replace
it with whatever query you want to run against your database.

You can copy and paste from your .sql file into the query editor.

Just make sure you do NOT toggle the edit mode back to the “assisted” mode,
because that would delete your carefully crafted query.

If you run into problems, feel free to come back, with enough detail that we
can understand what you’ve done, what went wrong, and what you expected
instead.

Good luck :slight_smile:

Antony.

1 Like

Hi @ihammami follow these steps .

  1. Create any panel and make it editable by click on edit button.

  1. Now select your sqldatabase connection name which you used for connection and paste your sql querry
1 Like

thank you for your answers but i still have question

  • grafana want that i have a time selection (select … as time ) so want can i do if i have no time column in the database table, or in the query that i want to execute.

thank you for your answers but i still have two worries:

  1. grafana want that i have a time selection (select … as time ) so want
    can i do if i have no time column in the database table, or in the query
    that i want to execute.

Tell us what sort of data you are trying to display in Grafana, and what sort
of graph you want it displayed as.

2.even if i paste my query in the “edit sql” and then execute it, no data
is displayed in the graph and the defaults values of a query are still the
same.

Please show a screenshot of what you are doing and what is going wrong.

Antony.

these are the screenshot of the first point:
when i delete time condition, or i have a query not containing time column i have no data displayed.

Capture3

If you are plotting a graph you need something along the X axis, usually time. What exactly are you trying to draw on the graph?

i want to drow in the x axe anything but time for exemple the name of the stop.
could you please tell me how to do that ?

I don’t think you can plot against against anything but time on the graph panel, I don’t know about the other panel types.

In my opinion Grafana is not the right tool for that requirement.

Antony.

if your data is not time related, use “select now() as time” for create the time series, and don’t use it.