WITH dataSource AS (
SELECT 1 a,'A' b,'X' c,10 d FROM DUAL
UNION ALL
SELECT 1 a,'A' b,'Y' c,11 d FROM DUAL
UNION ALL
SELECT 2 a,'B' b,'Y' c,20 d FROM DUAL
UNION ALL
SELECT 2 a,'B' b,'Y' c,21 d FROM DUAL
)
SELECT DISTINCT a
,first_value(b) over(partition by a order by b) b
,first_value(c) over(partition by a order by b) c
,first_value(d) over(partition by a order by b) d
,last_value(b) over(partition by a order by b) e
,last_value(c) over(partition by a order by b) f
,last_value(d) over(partition by a order by b) g
FROM dataSource
SELECT 1 a,'A' b,'X' c,10 d FROM DUAL
UNION ALL
SELECT 1 a,'A' b,'Y' c,11 d FROM DUAL
UNION ALL
SELECT 2 a,'B' b,'Y' c,20 d FROM DUAL
UNION ALL
SELECT 2 a,'B' b,'Y' c,21 d FROM DUAL
)
SELECT DISTINCT a
,first_value(b) over(partition by a order by b) b
,first_value(c) over(partition by a order by b) c
,first_value(d) over(partition by a order by b) d
,last_value(b) over(partition by a order by b) e
,last_value(c) over(partition by a order by b) f
,last_value(d) over(partition by a order by b) g
FROM dataSource