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)
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
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.
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.
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