Time elapsed in each value point


I have a measurement (influxdb) where I record different states of the equipment on a field name “state”. ej: 1=stop, 2=on, 3=failure, 4=normal, etc.

I have looked for documentation of how to get the time elapsed of each state and I could not find the solution. Somebody can tell me how?