Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2016
    Posts
    1

    Answered: Recursive SQL ,Db2

    Hi ,

    I need help in writing a query in recursive SQL. The input table EMPLOYEEDEPTClick image for larger version. 

Name:	table.png 
Views:	4 
Size:	4.7 KB 
ID:	17196

    The output will look likeClick image for larger version. 

Name:	Result.png 
Views:	5 
Size:	5.8 KB 
ID:	17197

  2. Best Answer
    Posted by mark.bb

    "Hi,

    You don't need any recursive SQL here.
    Code:
    select 
      case department when 'Science'     then name end Science
    , case department when 'Geography'   then name end Geography
    , case department when 'History'     then name end History
    , case department when 'Mathematics' then name end Mathematics
    from table(values
      ('Sudarsan', 'Science')
    , ('Seraj', 'Science')
    , ('Samrat', 'Geography')
    , ('Mitesh', 'Geography')
    , ('Wasim', 'History')
    , ('Robert', 'Mathematics')
    ) t (name, department)
    "


  3. #2
    Join Date
    Jul 2016
    Location
    Moscow
    Posts
    110
    Provided Answers: 13
    Hi,

    You don't need any recursive SQL here.
    Code:
    select 
      case department when 'Science'     then name end Science
    , case department when 'Geography'   then name end Geography
    , case department when 'History'     then name end History
    , case department when 'Mathematics' then name end Mathematics
    from table(values
      ('Sudarsan', 'Science')
    , ('Seraj', 'Science')
    , ('Samrat', 'Geography')
    , ('Mitesh', 'Geography')
    , ('Wasim', 'History')
    , ('Robert', 'Mathematics')
    ) t (name, department)
    Regards,
    Mark.

Tags for this Thread

Posting Permissions

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