DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Help on sql querry

  1. #1
    Join Date
    Sep 2000
    Posts
    384
    I need to write a sql querry where is

    i need to get the records like

    deptno empno empno empno empno
    10 23 24 25 27
    Radhakrishnan.M

  2. #2
    Join Date
    Sep 2000
    Posts
    384
    let we write the stament clearly

    Normally when we select we get records like

    empno deptno
    34 10
    35 10
    36 10
    37 20
    38 20
    39 20

    i need to get the records like

    deptno empno empno empno
    10 34 35 36
    20 37 38 39


    In access we will be able to do this .how about this in oracle in s sql statement.

    Radhakrishnan.M

  3. #3
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Personally, I'd do it with a Package. jmodic, chrisrlong or others may have some fancy decode/union/case statement...
    Jeff Hunter

  4. #4
    Join Date
    Apr 2001
    Posts
    118
    Yeah, we play around with DECODE, CASE, etc. to do bounded pivot queries. That is, we can very efficiently pivot the results from many rows into a single row assuming that we know the maximum number of rows to be pivoted. If there is no known bound, then the best solution that I've seen is to use a procedure like Jeff suggested.

    Some threads discussing bounded pivot solutions:

        Using CASE. (It's not the main post of the post, but it's in there.)

        Using math tricks.

        Using DECODE. (I can't find one right now, but you should be able to figure it out based upon the others).

    Also, the discussion between Jurij and Chris in this thread about DECODE vs. CASE is quite educational.

    And here is a thread where Jeff provided a procedure to do this.


    HTH,

    Heath

  5. #5
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Originally posted by Heath
    Also, the discussion between Jurij and Chris in this thread about DECODE vs. CASE is quite educational.
    When these two get into it, watch out. It's a regular battle of the minds...
    Jeff Hunter

Posting Permissions

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


Click Here to Expand Forum to Full Width