Plot bookingrequests

Hi,

I have a MySQL table with bookingrequests.
The table has a datetime field and a package_field (created, package_type).

I want to plot multiple lines. Each line should represent a package_type (gold, silber, platin, …) and show in the graph how many people have booked them per day.

How can I do this?

My current SQL statement looks like that. But it shows only the total amount of bookings within one day. But i want to split them by package_type:

SELECT 
  DATE(br.created) as time, 
  COUNT(*) as number_of_bookings
FROM 
  bookingrequest_bookingrequest AS br
JOIN 
  searchroom_building AS sb 
ON 
  br.building_id = sb.id 
WHERE
  $__timeFilter(br.created)
GROUP BY
  DATE(br.created)

You need to group by date (as you are doing now) AND by package_type column as well.

GROUP BY
  DATE(br.created), br.package_type

so each package_type will have generated own time series.

thank you for the fast response.

I still just see one graph.

SELECT 
  DATE(br.created) as time, 
  COUNT(*) as number_of_bookings
FROM 
  ws3mzguru.bookingrequest_bookingrequest AS br
JOIN 
  searchroom_building AS sb 
ON 
  br.building_id = sb.id 
WHERE
  $__timeFilter(br.created)
GROUP BY
  DATE(br.created), sb.package_type

What I am doing wrong?

Add package type in select of the query

This is basic mysql query question that is unrelated to grafana

SELECT 
  DATE(br.created) as time, 
  COUNT(*) as number_of_bookings,
  sb.package_type
FROM 
  ws3mzguru.bookingrequest_bookingrequest AS br
JOIN 
  searchroom_building AS sb 
ON 
  br.building_id = sb.id 
WHERE
  $__timeFilter(br.created)
GROUP BY
  DATE(br.created), sb.package_type

The “tabele” output is how i think it is correct but now it is drawing two lines. package_type and number of bookings.

What is wrong here?

have you chosen the right Time Series Format

I am not sure what you exactly mean.

Why do you have posted this four different select statements?


Is the output format correct now? For me it looks good, Not sure where the problem is coming form.

To emulate your data, disregard that and look on top of the query there is a Fornat drop down with table and time series choices

I changed it, but it is not helping. Do I need any kind of transform or anything else?

What version of grafana are you on?

9.5.2 => do i need to update?

If on 9.5.2 try transformation and then choose prepare time series and choose i think wide series. Keep playing with it

I tried all three options with no luck … should I consider to update to > 10?

1 Like

What does the data tab look like when you used transformation


Do you mean this view with “data tab”?

I found very hard to follow you. Plese post query and result from that query.

I guess:

SELECT 
  DATE(br.created) as time, 
  COUNT(*) as number_of_bookings,
  CAST(CAST(sb.package_type AS CHAR);AS CHAR) AS metric
FROM 
  ws3mzguru.bookingrequest_bookingrequest AS br
JOIN 
  searchroom_building AS sb 
ON 
  br.building_id = sb.id 
WHERE
  $__timeFilter(br.created)
GROUP BY
  DATE(br.created), sb.package_type

That metric column must be a string, not numeric type, so cast it to string.

1 Like

You are right. It works now!

SELECT 
  DATE(br.created) as time, 
  COUNT(*) as number_of_bookings,
  CAST(sb.package_type AS CHAR) AS metric
FROM 
  bookingrequest_bookingrequest AS br
JOIN 
  searchroom_building AS sb 
ON 
  br.building_id = sb.id 
WHERE
  $__timeFilter(br.created)
GROUP BY
  DATE(br.created), sb.package_type


But there is one last problem. If there is no value for a specifc data und package type. The value in empty but should be drawed as 0.

Can I change this behavior in Grafana or do I have to do this within my sql query?

That depends on used panel type.

I would use SQL. MySQL datasource has already macros, which will help you.

1 Like