0

I would like to format the data of below table as follows. Here on the value column, I want to maintain only on value for each of the duplicated rows.

input table

code    value
A       10
A       10
A       10
B       20
B       20
B       20
C       30
C       30
D       40

Expected result

code    value
A        10
A   
A   
B        20
B   
B   
C        30
C   
D        40
6
  • you would like to have null instead of value? what have you tried? Commented May 7, 2019 at 8:41
  • Yes null or zero is good for me Commented May 7, 2019 at 8:42
  • 1
    Are you using MySQL or Postgresql? Commented May 7, 2019 at 8:43
  • Am using Postgres Commented May 7, 2019 at 8:44
  • Do you want to update the table, or just get these values on output? Commented May 7, 2019 at 8:45

1 Answer 1

1

A combination of CASE and window function can solve your problem

select code, 
       case when t.rn = 1 then value else null end value
from (
    select row_number() over (partition by code, value order by value) rn,
           code, value
    from your_table
) t
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.