sql - Split a column into multiple columns -


select distinct account_num account order account_num; 

the above query gave below result

                 account_num                       1                       2                       4                       7                       12                       18                       24                       37                       45                       59 

i want split account_num column tuple of 3 account_num's (1,2,4);(7,12,18);(24,37,45),(59); last tuple has 1 entry there no more account_num's left. want query output min , max of each tuple. (please observe max of 1 tuple less min of next tuple). output desired shown below

                 1  4                  7  18                  24 45                  59 59     

edit: have explained requirement in best way could

this solution.

select * (select distinct min(val) over(partition gr) min_,                                             max(val) over(partition gr) max_                 (select val,                                          decode(trunc(rn / 3), rn / 3, rn / 3, ceil(rn / 3)) gr                                 (select val,                                              row_number() over(order val) rn                                                 (select distinct account_num account order account_num)))) order min_ 

updated

solution without analytic function.

select min(val) min_,        max(val) max_ (select val,              ceil(rn / 3) gr             (select val,                          rownum rn                         a_del_me)) group gr 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -