Home > other >  Convert excel formula to Oracle SQL
Convert excel formula to Oracle SQL

Time:07-17

How to convert excel formula to oracle sql. =A2&COUNTIF($A$2:A2,A2)

In excel in have 2 columns: order and helper, i am running the above formula in excel column 2, which basically copy data from order column and add suffix to same order_id.

<table>
  <thead>
    <tr>
      <th>Order_id</th>
      <th>Helper</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>45235</td>
      <td>452351</td>
    </tr>
    <tr>
      <td>45235</td>
      <td>452352</td>
    </tr>
  </tbody>
</table>

enter image description here

CodePudding user response:

You can use row_number() to acheive the same.Please find the db fiddle

    with data as(
      select 
        45235 order_id 
      from 
        dual 
      union all 
      select 
        45235 order_id 
      from 
        dual
    ) 
    select 
      order_id, 
      order_id || row_number() OVER(
        partition by order_id 
        order by 
          order_id
      ) 
    from 
      data order dy 1;
  • Related