How to synthesize three pieces of data from the database into one piece of data

The table structure before

is like this

clipboard.png
2

clipboard.png
sql4alias_namealias_name2alias_name3

clipboard.png

Sep.26,2021

use the window function of oracle. The field of the screenshot cannot be seen clearly. Please indicate it in the way of col1,col2,col3

.
select *
from (
    select t.*, 
      row_number() over (partition by col1, col2, col3, col4 order by alias_id) as rank_id,
      lead(amount) over (partition by col1, col2, col3, col4 order by alias_id) as alias_name2,
      lead(amount, 2) over (partition by col1, col2, col3, col4 order by alias_id) as alias_name3
    from t
    order by col1, col2, col3, col4, alias_id
)
where rank_id = 1

according to the query results above, you can save to the temporary table first, and then reinsert the data from the temporary table after the source table is emptied.

Menu