I'm struggling to find a way to get consecutive pairs in a column of a table but failed so far. To explain more specifically, let me give an example.
Let's say I have a table (t1) with 1 column (col1) of char as follows:
col1
------
a
a
a
c
e
a
g
i
What I want to get is consecutive pairs like
(a,a) (a,a) (a,c) (c,e) (e,a) (a g) (g,i)
.
For example, building a new table(t2) which has a column(col2) of string as follows:
col2
------
a,a
a,a
a,c
c,e
e,a
a,g
g,i
(if I can exclude the pairs of same value (e.g. (a,a)), it would be better)
Please assume that there is no analytic function like lag() and unable to use pl/sql. I have to solve this problem with basic sql statements.
I have a quite simple sql query to solve this kind of problem as follow:
select t1.col as col1, min(t2.col) as col2
from table1 t1 inner join table1 t2 on t2.col > t1.col
group by t1.col
order by t1.col
But this query is working when we assume there is no duplication.
Please help. Any comment or idea would be very thankful.