sql - how to get the even and odd column separately with separate column by query -
i have input:
id
1 2 3 4 5 6 7 8 9 10
i want , odd columns separately columns in specified output this
id col
1 2 3 4 5 6 7 8 9 10
here id , col separate columns id contains odd number , col contains number specified input
select min(id) id, max(id) col yourtable group floor((id+1)/2)
for ids 1
, 2
, (id+1)/2
2/2
= 1
, 3/2
= 1.5
, respectively, , floor
returns 1
both of them. similarly, 3
, 4
, 2
, , on. groups input rows pairs based on formula. uses min
, max
within each group lower , higher ids of pairs.
Comments
Post a Comment