select
ID,
segment_numeric,
created_on,
CASE WHEN FirstId = 1 then 'First' else 'Last' end as RankNumber
from
(
select
RANK() over (partition by id order by created_on asc) as FirstId,
RANK() over (partition by id order by created_on desc) as LastId,
*
from
Test
)s
where FirstId = 1 or LastId = 1

SELECT *
FROM (
SELECT *,
FIRST_VALUE(segment) OVER (PARTITION BY id ORDER BY created_on) AS First,
LAST_VALUE(segment) OVER (PARTITION BY id ORDER BY created_on) AS Last
FROM Table
)t
WHERE First=Last

;With CTE
AS
(
SELECT id
FROM
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY created_on) AS Seq,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY created_on DESC) AS BSeq
FROM Table
)t
WHERE Bseq=1
OR Seq=1
GROUP BY id
HAVING COUNT(DISTINCT segment) =1
)
SELECT t.*
FROM Table t
JOIN CTE c
ON c.id = t.id