mysql - Place a footer row as an header row of a group of rows -


i have table following :

 rfa_yea | rfa_idx |                      rfa_dsp                       | rfa_tpr ---------+---------+----------------------------------------------------+---------  2013    |       1 | pigato verm.no/ross/ormeasco cl75                  |  2013    |       2 | estate\134134134047 bicchiere sing.verde           |  2013    |       3 | rif. trn. n. 17 del 17/04/2013 cassa n. 00001      | c  2013    |       4 | bib.red bull lat.cl25 ener.dri                     |  2013    |       5 | bib.red bull lat.cl25 ener.dri                     |  2013    |       6 | shopper 30x60 maxi x 1000                          |  2013    |       7 | shopper hd 27x50 medie x 1000                      |  2013    |       8 | pigato verm.no/ross/ormeasco cl75                  |  2013    |       9 |  * sconto subtotale                                |  2013    |      10 | rif. trn. n. 19 del 17/04/2013 cassa n. 00001      | c 

the record field rfa_tpr marked 'c' header of group of rows came before it. need place row header of group of rows instead of footer(separator) @ moment, want retrieve result set following :

 rfa_yea | rfa_idx |                      rfa_dsp                       | rfa_tpr ---------+---------+----------------------------------------------------+---------  2013    |       3 | rif. trn. n. 17 del 17/04/2013 cassa n. 00001      | c  2013    |       1 | pigato verm.no/ross/ormeasco cl75                  |  2013    |       2 | estate\134134134047 bicchiere sing.verde           |  2013    |      10 | rif. trn. n. 19 del 17/04/2013 cassa n. 00001      | c  2013    |       4 | bib.red bull lat.cl25 ener.dri                     |  2013    |       5 | bib.red bull lat.cl25 ener.dri                     |  2013    |       6 | shopper 30x60 maxi x 1000                          |  2013    |       7 | shopper hd 27x50 medie x 1000                      |  2013    |       8 | pigato verm.no/ross/ormeasco cl75                  |  2013    |       9 |  * sconto subtotale                                | 

is there solution sql ? solution should work on each of these kind of database server : mssql, postgresql , mysql.

note

i can have multiple separators(footers) rows, not 2 in example ...

select a.rfa_yea ,         a.rfa_idx ,         a.rfa_dsp ,         a.rfa_tpr table1 inner join table1 c on a.rfa_idx <= c.rfa_idx , c.rfa_tpr = 'c' group  a.rfa_yea ,         a.rfa_idx ,         a.rfa_dsp ,         a.rfa_tpr order min(c.rfa_idx), a.rfa_tpr desc, a.rfa_idx  

sql server demo

mysql demo

postgresql demo


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -