Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2015
    Posts
    31

    Unanswered: field incremental

    Hello,

    I would like to fill a incremental field in this way , each 2 entities I would like to increment the value of the field by 1.
    Does someone knows a way to do this ?
    Thank You -

    incremental_field entity member
    1 entity1 member1
    1 entity1 member2
    1 entity2 member3
    1 entity2 member4
    2 entity3 member6
    2 entity4 member7
    2 entity4 member8
    2 entity4 member9

  2. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hello,

    try this:
    Code:
    select 
      1+(dense_rank() over(order by entity)-1)/2 as incremental_field
    , entity, member
    from table(values
      ('entity1', 'member1')
    , ('entity1', 'member2')
    , ('entity2', 'member3')
    , ('entity2', 'member4')
    , ('entity3', 'member6')
    , ('entity4', 'member7')
    , ('entity4', 'member8')
    , ('entity4', 'member9')
    ) t (entity, member)
    Regards,
    Mark.

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    oops did not catch whole intent of question.
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •