help me for writing an sql query I want to write a query to select all the rows where the row value changes from previous row. Please see the image attached above.

CREATE TABLE traffview.status_data (
    id serial NOT NULL,
    site_id integer,
    rtc timestamp without time zone,
    sigplan smallint,
    PRIMARY KEY (id)
    );

INSERT INTO traffview.status_data(
    id,
    site_id,
    rtc,
    sigplan
    )
    VALUES (?, ?, ?, ?);
This should work:

WITH cte(id, controller_id, RTC, signal_plan, rw) AS 
(
     SELECT
         id,
         controller_id,
         RTC,
         signal_plan,
         ROW_NUMBER() OVER (PARTITION BY signal_plan ORDER BY id) rw
     FROM your_table)

     SELECT
         id,
         controller_id,
         RTC,
         signal_plan
     FROM cte
     WHERE rw = 1;