PDA

View Full Version : How to order intercalary rows



SeaAnne
10-22-2015, 09:16 AM
Hi!
I have 1 table with State "On" and "Off" that belong to a certain machine, I want to order Off On Off On Off On considering that the "Off" following by the "One" are in the same machine.


Input:
State Machine
On A
On F
Off H
On D
On H
On A
Off B
Off B
Off F
Off K
On F
Off D
On B
Off A
....


Output:
State Machine
Off A
On A
Off B
On B
....




I really appreciate your help,
:)

jonh
10-22-2015, 12:25 PM
SELECT distinct state, machine
FROM states
order by machine, state

assuming your table is called 'states'