Merged data in the MySQL table and visualize in the database

Hi, currently I am visualizing my data that collected from the voltage sensor that save inside the MySQL database. I wish to make condition if the last voltage value with ‘1’ and current value with ‘1’, the current value becomes ‘0’, is that possible to apply this logic using Grafana? Any others recommendation to achieve this condition?
I want to make this condition due to the reason that sometime the machine cut more than 5s and the data collected each 5 seconds to the database.