Skip to content
Advertisement

SQL how to fill out first line of group with value and other values to null

Actually i have a select statement which contains a group by

I would like this :

How to do that (test value fill in first row group) with sql (pgsql) ? thanks !

I tried Partition by…

Advertisement

Answer

demo:db<>fiddle

  1. Enumerate all records of an ordered group to find the first one using the row_number() window function
  2. Keep the value if the row number is 1, NULL else
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement