Insert blank row between groups of rows and sorted by ID in sql

前端 未结 2 1991
一个人的身影
一个人的身影 2020-12-21 05:54

I have a table which has the following columns and values

ID       TYPE     NAME
1      MAJOR      RAM
2      MAJOR      SHYAM
3      MAJOR      BHOLE
4              


        
2条回答
  •  情书的邮戳
    2020-12-21 06:17

    I agree with billinkc. In a sequential mind, like mine, it can occur different. The approach is to use a cursor and insert the records into a temp table. This table can have a column, INT type, lets say it is called "POSITION" which increments with every insert. Check for ID changes, and add the empty row everytime it does. Finally make the SELECT order by "POSITION".

    My context was: An interface that dinamically adjust to what the user needs, one of the screens shows a payment table, grouped by provider with the approach early mentioned. I decided to manage this from database and skip maintainance for the screen at client side because every provider has different payment terms.

    Hope this helps, and lets keep an open mind, avoid saying "don't do this" or "this is not what SQL was designed for"

提交回复
热议问题