Pie Chart, SQL, Percentage of boolean Value over Time

Hello Everyone! Im new to this Forum, appologies if this Topic isnt in the right Sub.

What Grafana version and what operating system are you using?
Grafana v8.2.3

  • What are you trying to achieve?
    Summarizing multiple boolean Values over a given Period of time and displaying it as percentage in a Pie Chart.

  • How are you trying to achieve it?
    I am very unfammiliar with SQL and Databases in General. Appologies fot that!
    Im a PLC technitian an somehow managed to get involved in a SQL Project…

Via the count Function im am Able to Count the Number of Times that the boolean Datapoints have gone from False to True within a given Time (Timefilter Function)

This is how my Data Table in Microsoft SQL looks like:
SQL_boolean_Timeseries
Here is what i have so far in Grafana:

This Pie Chart represents not the actual Status of the Maschine as it only Counts the rising Edge of the boolean Values. So im looking for a Way to Count the Percentage of those boolean Values over a specific Time Range.
E.g.: Time Range (2022-10-02T09:00:00 until 2022-10-02T10:00:00)
boolean Auto was True from 2022-10-02T09:00:00 until 2022-10-02T09:40:00
boolean Fault was True from 2022-10-02T09:40:00 until 2022-10-02T09:45:00
boolean Waiting was True from 2022-10-02T09:45:00 until 2022-10-02T09:55:00
boolean Auto was True from 2022-10-02T09:55:00 until 2022-10-02T10:00:00

This Example should lead to the follwing Result in the Pie Chart:
75% Auto; Fault 8,33%; Waiting 16,66%

Any Help to Achive this Goal will be greatly Appreciatet! And sorry for my English if there are some Things not easy to Understand.