Forum Discussion

dbodestrom's avatar
dbodestrom
Regular Visitor
7 years ago

Increment/decrement table columns

Hi!

I have a table with two columns, column A and column B. Column A describes city of origin and column B describes city of destination.

Between every row in the table i want to create a new row with the city of destination in row 1 column B as new city of origin (row 2 column A) and the city of origin from the original row 2 as city of destination in the new row 2. Here comes an example,

I want this:

                 Column A,       Column B

Row 1       Boston             New York

Row 2       Philadelphia     Pittsburgh

Row 3       Columbus        Washington DC

 

To become this

                 Column A,       Column B

Row 1       Boston             New York

                 New York         Philadephia
Row 2       Philadelphia     Pittsburgh

                 Pittsburgh        Columbus
Row 3       Columbus        Washington DC

Is there som way do this?

Thank you :)

1 Reply

  • tex628's avatar
    tex628
    Icon for Community Champion rankCommunity Champion

    I have a really tedious way that might work :-) 

    * Duplicate the query so you have #1 & #2
    * Add index to both queries
    * Split Column A and B in query #2 into two new queries, #3 & #4
    * Make sure that you maintain the index from #2 in both #3 & #4
    * Add +1 to the index of #4, which should hold a Column B
    * Merge #3 & #4 back together on index
    * Swap the names of the columns - A to B and B to A
    * Append #1 & #2

    I hope you can get something from this! :)

    / J