sql - How to split a table in 4 groups? -


i have table 2 columns. seq column goes 1 100.

part_no             seq a23                  1 b88                  2 c34                  3 a43                  4 b48                  5 e11                  6 a87                  7 e64                  8 ...till seq 100 

i want split table below:

part_no_a             part no_b            part_no_c            part_no_d a23                     b88                  c34                   a43 b48                     e11                  a87                   e64 

i use conditional aggregation modulo function:

select max(case when seq % 4 = 1 part_no end) part_no_a,        max(case when seq % 4 = 2 part_no end) part_no_b,        max(case when seq % 4 = 3 part_no end) part_no_c,        max(case when seq % 4 = 0 part_no end) part_no_d databasetable t group ((seq - 1) / 4); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -