Pivot min & max in single row.

Greetings,
Please help me in this case...
Can we get the columns as,
Dimension, # Count, MAX (# Count), MIN (#Count) all in one line with separate values but separate min, max & count in pivot.
also imagine for multiple rows .
this report is seen on year level but the min & max shld be on a level below, quarter.
i.e. this report will give the total count for all quarters, max no of count from 4 quarters & same for min.
---------|_--____________YEAR_____________
Dim ---|# Count -- MAX (Count) --- MIN (Count)
Please help.
Thanks,
Dev

I'm not sure if this is what you're after, but using Aketi's tabibitosan method:
with results as (select someid,
                        adate,
                        row_number() over (order by adate) rn,
                        dense_rank() over (partition by someid order by adate) dr,
                        row_number() over (order by adate) - dense_rank() over (partition by someid order by adate) diff
                 from   t1)
select someid,
       min(adate) min_adate,
       max(adate) max_adate
from   results
group by someid, diff
order by min(adate);
    SOMEID MIN_ADATE                       MAX_ADATE                     
       756 25/01/2010 07:22:57.000000      25/01/2010 07:23:58.000000    
       822 25/01/2010 07:24:44.000000      25/01/2010 07:25:33.000000    
       770 25/01/2010 07:29:53.000000      25/01/2010 07:30:11.000000    
       816 25/01/2010 08:03:02.000000      25/01/2010 08:27:13.000000    
       770 25/01/2010 08:54:04.000000      25/01/2010 08:54:16.000000    
       822 25/01/2010 08:58:07.000000      25/01/2010 08:58:09.000000

Similar Messages

  • Find MIN, MAX of multiple rows from multiple columns

    Hello,
    I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
    For Example: (C: Column, R: Row, N - NULL/Blank)
    C:____1____2____3____ 4____Max
    R:____20___22___13____4____*22*
    R:____N____N____32____14___*32*
    R:____N____12____N____N____*12*
    That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
    So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
    Here is my current code:
    CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END

    Hi Thank you for your feedback, unfortunately, I just found out that EVALUATE Function is disabled in our environment for security reasons, so the only other way I've discovered is this:
    The problem is that none of the conditions in the case statement are met--so the column is set to null. You can add a WHEN statement (section 2 below) to catch the nulls. There are five cases to consider:
    Case 1: begin insp > bad order
    Case 2: begin insp < bad order
    Case 3: bad order only (begin insp is NULL)
    Case 4: begin insp only (bad order is NULL)
    Case 5: both begin insp is NULL and bad order is NULL
    1) If bgn-crm-insp-ob > report-bo-ob then bgn-crm-insp-ob
    (Case 1)
    CASE WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob') > filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    2) If report-bo-ob is NULL then bgn-crm-insp-ob
    (Case 4, 5) for case 5, you will get NULL
    WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') IS NULL THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    3) Else report-bo-ob
    (Cases 2, 3)
    ELSE filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') END
    Hopefully this works, I'll give feedback if it does, or if you have any further suggestions please submit, again, THANK YOU SO MUCH ANYWAYS!

  • How to Get the min,max and original values in a single query

    Hi,
    I have a task where in i have to the min , max and the original values of  a data set .
    I have the data like below and i want the target as well as mentioned below
    SOURCE
    DATASOURCE
    INTEGRATIONID
    SLOT_DATE
    SLOT1
    SLOT2
    SLOT3
    SLOT4
    SLOT5
    SLOT6
    SLOT7
    SLOT8
    SLOT9
    SLOT10
    1
    101
    201111
    100
    100
    200
    100
    100
    100
    300
    300
    300
    300
    1
    101
    2011112
    200
    200
    200
    200
    100
    100
    100
    100
    200
    300
    TARGET
    DATASOURCE
    INTEGRATIONID
    SLOT_DATE
    SLOT_VALUE
    SLOT MIN
    SLOT_MAX
    SLOT NUMBER
    1
    101
    201111
    100
    1
    2
    SLOT1
    1
    101
    201111
    100
    1
    2
    SLOT2
    1
    101
    201111
    200
    3
    3
    SLOT3
    1
    101
    201111
    100
    4
    6
    SLOT4
    1
    101
    201111
    100
    4
    6
    SLOT5
    1
    101
    201111
    100
    4
    6
    SLOT6
    1
    101
    201111
    300
    7
    10
    SLOT7
    1
    101
    201111
    300
    7
    10
    SLOT8
    1
    101
    201111
    300
    7
    10
    SLOT9
    1
    101
    201111
    300
    7
    10
    SLOT10
    1
    101
    2011112
    200
    1
    4
    SLOT1
    1
    101
    2011112
    200
    1
    4
    SLOT2
    1
    101
    2011112
    200
    1
    4
    SLOT3
    1
    101
    2011112
    200
    1
    4
    SLOT4
    1
    101
    2011112
    100
    5
    8
    SLOT5
    1
    101
    2011112
    100
    5
    8
    SLOT6
    1
    101
    2011112
    100
    5
    8
    SLOT7
    1
    101
    2011112
    100
    5
    8
    SLOT8
    1
    101
    2011112
    200
    9
    9
    SLOT9
    1
    101
    2011112
    300
    10
    10
    SLOT10
    e
    so basically i would first denormalize the data using the pivot column and then use min and max to get the slot_start and slot_end.
    But then i
    can get the min and max ... but not the orignal values as well.
    Any thoughts would be appreciated.
    Thanks

    If you want to end up with one row per slot per datasource etc, and you want the min and max slots that have the same value as the current slot, then you probably need to be using analytic functions, like:
    with t as
    (SELECT 1 datasource,101    INTEGRATIONID, 201111     slotdate, 100    SLOT1, 100        SLOT2,    200    slot3, 100    slot4, 100    slot5, 100    slot6, 300    slot7, 300    slot8, 300    slot9, 300 slot10 FROM DUAL  union all
    SELECT 1,    101,    2011112,    200,    200,    200,    200,    100,    100,    100,    100,    200,    300 FROM DUAL),
    UNPIVOTED AS
    (SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,1 SLOT,SLOT1 SLOT_VALUE
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,2 SLOT,SLOT2
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,3 SLOT,SLOT3
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,4 SLOT,SLOT4
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,5 SLOT,SLOT5
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,6 SLOT,SLOT6
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,7 SLOT,SLOT7
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,8 SLOT,SLOT8
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,9 SLOT,SLOT9
    FROM T
    UNION ALL
    SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,10 SLOT,SLOT10
    FROM T)
    select DATASOURCE,INTEGRATIONID,SLOTDATE,slot,slot_value,min(slot) OVER (partition by datasource,integrationid,slotdate,rn) minslot,
        max(slot) OVER (partition by datasource,integrationid,slotdate,rn) maxslot
    FROM   
      select DATASOURCE,INTEGRATIONID,SLOTDATE,max(rn) over (partition by datasource,integrationid,slotdate order by slot) rn,slot,slot_value
      FROM
        (SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,slot,slot_value,
              case when row_number() over (partition by datasource,integrationid,slotdate order by slot) = 1 or
              lag(slot_value) over (partition by datasource,integrationid,slotdate order by slot) <> slot_value
                  then row_number() over (partition by datasource,integrationid,slotdate order by slot)
                  ELSE null
                  END rn
        from unpivoted
    order by DATASOURCE,INTEGRATIONID,SLOTDATE,slot 

  • Min Max Planning to replenish from a single sub inventory

    I am new to this site but could certainly use some help in a problem I am having. I am on a team in the process of implement discrete manufacturing. Here is the problem I am having. I am trying to set up min/max replenishment to a specific sub inventory. We currently have a centralized fabricated (make parts) store room. From that store room we move parts to variuos supermarkets with in the factory. From the supermarkets parts are component picked or kan ban replenished. The problem that I am having is that I want the replenishment trigger back to the sheet metal fabrication area to come from the "Centralized Make" parts storeroom. It is currently adding up all the locations or sub inventories the part number resides in to include RIP. I am being told that there is no way to limit the trigger to a single sub inventory.

    Sandeep, Thanks I was able to generate and run the report and it did look only that the specified sub inventory and suggested the reorder qty properly. After running the report under the item number it says "unable to generate requisition" How does the fabrication area get a signal to begin the fabrication process, create a discrete job or create a planne order or something? So far your recommendations have been right on target! Again thankyou.

  • Max number of rows to display in a pivot table

    I have a pivot table with two row levels and I need to fix the max amount of rows to display at the second level to five. Can I do that on excel 2013?
    Example
    Row Levels
    Machine A
    Part 1 (to be displayed)
    Part 2 (to be displayed)
    Part 3 (to be displayed)
    Part 4 (to be displayed)
    Part 5 (to be displayed)
    Part 6 (not displayed)
    Machine B
    Part 1 (to be displayed)
    Part 2 (to be displayed)
    Part 3 (to be displayed)
    Part 4 (to be displayed)
    Part 5 (to be displayed)
    Part 6 (not displayed)
     and so go on. 

    Hello, 
    you can use a filter to display only the top 5 items of the second level, based on their value. To do that, right-click on a label in the second level, then select Filter > Top 10.  Change the 10 to a 5 in the next dialog.
    You can also create a label filter, but it only takes one filter condition.
    Another way is to select the rows you don't want to be shown, then use right-click > Filter > Hide Selected Items
    cheers, teylyn

  • Pivot view  - how to find min & max on a  level lower than selected..

    Hi all,
    we have a pivot view having structure.
    Year
    Dept |Count| Min | MAX |
    ABC | 87 | | |
    XYZ | 44 | | |
    Can we find out the min & max in the current year selected on quarter level & not on year and no show quarter on report. I.e the min count & max value of count in the 4 quarters.
    also for below structure.
         Year
    | Q1 | Q2 | Q3 | Q4 |
    Dept |Count| Min | MAX |Count| Min | MAX |Count| Min |MAX | Count| Min | MAX|
    ABC | | | | | | | | | | | | |
    XYZ | | | | | | | | | | | | |
    similarly find on quarter & for quarter we want the min & max on month level. i.e minimum & max in 3 months under that quarter.
    If we set the aggregation level as Min in max in pivot itself it shows the min & max same as the count as it calculates on the year level.
    Thanks,
    Dev

    Using hierarchies with exception aggregation can give strange results when aggregating to the parent nodes of the hierarchy. Recommendations:
    1) check whether the results are still wrong if you deactivate the hierarchy view
    2) build you exception aggregations globally. That is, do not define the exception aggregation in the structure of your query. Build it as a CKF on your InfoProvider.
    3) if the above steps don't work, perhaps you can use APD or get the exception aggregations calculated in the load to the InfoProvider rather than in BEx

  • How to find max value in single row

    i would like to know that,
    how can i display maximum value among several values in a single row of table
    example : i have to get value 5
    among 1 2 3 4 5 values of same row.

    Take a look at GREATEST function.
    C.
    Link to documentation added
    Message was edited by:
    cd

  • How to get the maximum/largest value in a single row?

    I have a simple Pivot table view with dollars as the measure, months on the columns and accounts on the rows.  I want to highlight the month that had the largest value.  E.g. so if the dollar values for account Revenue are 10 for Jan, 11 for Feb, 50 for Mar and 0 for the rest of the months, then I want to highlight the cell with 50 green. So essentially I need to be able to identify the max value in a row in the pivot table. 
    If I add a max calculation, it returns the top value across all columns and rows. A Rank calculation also returns rankings across all columns and rows. How can I determine the largest value in a single row?
    Thanks
    J

    In general you have to go by level based measures. Just tweak it as max(revenue by Year)
    Just do it in Criteria tab and see how it works and I thing rest you know how to do

  • To make Three row values in a single row

    Hi,
    Below is the Table Format i have.
    Here for the first Mail_ID i have 3 mail addresses.similarly for second ID too.
    I want First three rows to be in a single row.and so on...
    Plz help in doing this.
    Thanks 
    Deepa

    Deepa,
    Check if this helps.. Does dynamic conersion of data to columns ..
    --Your Email table
    create table #temp (mailid int,to_mail varchar(100))
    insert #temp select 1,'[email protected]'
    insert #temp select 1,'[email protected]'
    insert #temp select 1,'[email protected]'
    insert #temp select 2,'[email protected]'
    insert #temp select 2,'[email protected]'
    insert #temp select 3,'[email protected]'
    --Constructing a temp table to hold data with row_numbers
    select *,row_number() over(partition by mailid order by to_mail) as rn
    into #t
    from #temp
    --declaration of variables
    declare @n int,@list varchar(max),@sql nvarchar(max)
    set @n=(select max(rn) from #t)
    --Population of list to form the dynamic query
    ;with cte
    as
    select cast(',[email1]' as varchar(max)) as ch,1 as num
    UNION ALL
    select cast(ch+',[email'+cast((num+1) as varchar(100))+']' as varchar(max)) as ch,num+1 as num
    from cte where num<@n
    select top 1 @list=stuff(ch,1,1,'')
    from cte
    order by num desc
    --Formulating the complete dynamic query
    set @sql='
    select mailid,'+@list+'
    from
    select mailid,to_mail,''email''+cast(rn as varchar) as emailnum from #t
    ) tab
    PIVOT
    max(to_mail) for emailnum in ('+@list+')
    ) pvt'
    exec sp_executesql @sql
    --clean up
    drop table #t
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Merging two results into a single row

    Hi, Everyone... I think this is a weighted question and I feel like it's a bit difficult to phrase, so if it doesn't make sense - let me know and I'll try to clarify or provide some more concrete examples (if I can) :)
    I have a few tables inner joined in my sql query - I'd post the entire query here but it's lengthy and will probably add a bit more confusion so let's start with theorizing - where the results sometimes generate more than one row. If more than one row exists, I'd like to take the lowest number in one field and the highest number in another field, and display them on a single row.
    For instance, when I join the PERIOD and SCHEDULE tables, the PERIOD table might provide two rows like the following:
    SCHEDULE_ID      PERIOD_ID      START_TIME    END_TIME
    123               100           32820          35640
    123               101           35940          38760My final result should take the lowest START_TIME and the highest END_TIME, even if they exist is separate rows.
    START_TIME     END_TIME
    32820           38760It doesn't seem easy to me so if someone can make sense of this - you deserve an award. :) If I can provide some more clarification, please let me know. Thanks for any help. Oracle 11g
    Edited by: nage62587 on Sep 27, 2012 11:32 AM

    nage62587 wrote:
    Thanks! I'll try that... I have more than these columns in the result and I'm thinking a Group By likely wouldn't work - I will try but in the event it doesn't, does anyone else have any other suggestions?Group by is the correct way to do this. You group several rows of output into one row. Then you decide which values from inside that group you want to see. This is certainly possible. There are more aggregation functions available than you might think, not only min/max, also min/max + KEEP, count(case expression) and so on.

  • Min/Max  Internal Orders 1 Requisition

    We are running Min/Max planning to replenish stock in an "Emergency Warehouse" organization. The requisition import kicks off internal orders to a replenishment organization. The planner in the replenishment organization would like one order for each Min/Max run. The requisition group-by default in Purchasing parameters is vendor yet we are still seeing one unique requisition for each item thus creating one unique internal sales order per item. Thoughts?

    Stick wrote:
    The requisition group-by default in Purchasing parameters is vendor yet we are still seeing one unique requisition for each item thus creating one unique internal sales order per item. Thoughts?In this case the requisitions will not be grouped by Vendor because the supply source is Inventoy which is creating internal requisitions and not purchasing requisition (source is Supplier/ Vendor).
    It is important to know how you are importing requisitions and what value is specified for Group By parameter during import. The value you setup in Purchasing Options defaults in the Requisition Import request parameter screen, but this can be changed before submission. So it is possible in your case that requisitions are imported using a different group by than what is specified in Purchasing Options.
    From the list of different group by options available (All, Buyer, Category, Item, Supplier) you can probably use 'Location' during requisition import.
    Location: Group requisition lines for each delivery location on a separate requisition.
    But this will not guarantee 100% success because:
    - If you import requisitions with source as INV then those can include requisitions from different INV sources generated from Reorder, Kanban etc having same delivery location. In that case all those requisitions will be grouped under a single header having same location.
    - there may be different users running requisition import manually and some may forget to change this group by parameter (defaulted from purchasing options) while importing Min-Max planned requisitions (again they cannot segregate Min-Max, they can just specify INV as source)
    A better solution would be to use the oracle provided custom hook (po_reqimp_pkg.post_validate_user_extensions) for requisition import to populate the GROUP_CODE column in PO_REQUISITIONS_INTERFACE table. The logic inside the hook should identify the rows in the interface table generated from each run of Min-Max and populate a unique value for all those rows in the GROUP_CODE column. You need a small piece of code to be added inside the hook.
    You can also use REQ_NUMBER_SEGMENT1 column in the interface table to populate an unique value for all rows you want to group together. But in this case the value you specify will become the requisition number if there are no conflicts with the requisition number rule. Both these column, when populated, have precedence over Group by parameter. 1st priority GROUP_CODE (if populated). If GROUP_CODE is not populated then it checks REQ_NUMBER_SEGMENT1. If this is also blank then it uses Group By parameter.
    Thanks
    Supro

  • Joining query with single row result

    dear all,
    i have two tables
    create table item(item_id number primary key,
    item_desc varchar2(200));
    create table item_properties(item_id number references item(item_id),
    property_name varchar2(20),
    property_value varchar2(100));i insert the following records
    insert into items values(1,'CPU');
    insert into item_properties values(1,'RAM','2gb');
    insert into item_properties values(1,'PROCESSOR','2ghz');
    insert into item_properties values(1,'HARDDISK','2ghz');
    commit;now i want a query which produce the following results
    item_id      RAM      PROCESSOR         HARDDISK
    1              2gb        2ghz              2TBHow to generate this result?
    i have create a query but it generate multiple rows, instead i need in a single row like above.
    select i.item_id,p.property_value from items i , item_properties p
    where i.item_id=p.item_id and i.item_id=1;Kind thanks.
    Edited by: Maahjoor on May 7, 2013 12:22 AM

    select i.item_id,
           max(decode(p.property_name,'RAM',p.property_value)) ram,
           max(decode(p.property_name,'PROCESSOR',p.property_value)) processor,
           max(decode(p.property_name,'HARDDISK',p.property_value)) hd
    from items i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    group by i.item_id;Or pivot in 11g
    with details as
    select i.item_id,p.property_name,p.property_value
    from item i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    select *
    from details
    pivot
       max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK')
    );Edited by: jeneesh on May 7, 2013 1:04 PM

  • How to convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • Flatten rows into a single row

    Hi All,
    I have a table1 with records and PK for table 1 is (Date,Time).
    All I have to do is for a particular transaction, I have to get all the records and flatten them into a single row.
    For ex: Table 1 has the following
    Date Time Col1 Value
    08/03/2010 10:00am Employee_name John
    08/03/2010 10:00am Employee_ID 20
    08/03/2010 10:00am Salary 10000
    Now I have a table 2 which has the following structure:
    Date Time Employee_name Employee_ID Salary
    08/03/2010 10:00am John 20 10000
    Please let me know how to achieve this.,
    Thank You.

    Hi,
    Are you saying that you want to create table2, given table1?
    Displaying one column from many rows as if they were many columns on one row is called a Pivot , and here's one way to do it:
    SELECT       date_time
    ,       MIN (CASE WHEN col1 = 'Employee_name' THEN value END)     AS employee_name
    ,       MIN (CASE WHEN col1 = 'Employee_ID'      THEN value END)     AS employee_id
    ,       MIN (CASE WHEN col1 = 'Salary'      THEN value END)     AS salary
    FROM       table1
    GROUP BY  date_time
    ;Whenever you have a question, say what version of Oracle you're using.
    The query above works in Oracle 8.1 and up, but it might be simpler using the SELECT ... PIVOT feature that was introduced in Oracle 11.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements), and also post the results you want from that data.

  • Combining Multiple Rows into single row with multple columns

    Hi Experts,
    I have the following requirement, kindly help me.
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
    ID NAME DEPT1 DEPT2 DEPT3
    1 Sam 10 20
    2 alex 30 40 50
    3 vinod 60 70
    It's urgent requirement, kindly help me.
    Thanks in advance.

    Right I've had my drink, so what was this "urgent" question then?
    798616 wrote:
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
    If you understand how SQL statements are executed it's along these lines...
    1. Open Cursor
    2. Parse SQL statement and determine columns
    3. Bind in any input values
    4. Fetch data
    5. Bind out values to columns
    6. Repeat step 3 until no more data
    7. Close cursor
    Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
    If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
    What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
    Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
    It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
    If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
      2  --
      3  select deptno
      4        ,max(decode(rn,1,ename)) as ename1
      5        ,max(decode(rn,2,ename)) as ename2
      6        ,max(decode(rn,3,ename)) as ename3
      7        ,max(decode(rn,4,ename)) as ename4
      8        ,max(decode(rn,5,ename)) as ename5
      9        ,max(decode(rn,6,ename)) as ename6
    10        ,max(decode(rn,7,ename)) as ename7
    11        ,max(decode(rn,8,ename)) as ename8
    12        ,max(decode(rn,9,ename)) as ename9
    13        ,max(decode(rn,10,ename)) as ename10
    14  from t
    15  group by deptno
    16* order by deptno
    SQL> /
        DEPTNO ENAME1     ENAME2     ENAME3     ENAME4     ENAME5     ENAME6     ENAME7     ENAME8     ENAME9     ENAME10
            10 CLARK      KING       MILLER
            20 ADAMS      FORD       JONES      SCOTT      SMITH
            30 ALLEN      BLAKE      JAMES      MARTIN     TURNER     WARD
    SQL>

Maybe you are looking for

  • BP telephone and mobile change history report

    Hi, Requirement: We have a new requirement to create a new report that will display the change history of a customer who has done changes in their mobile or telephone number during a specific period. My approach was: Read the cdhdr data based on the

  • Safari 5.1.2 / Lion question

    Is it my css or Safari running in Lion that displays the blue border around hover links? Regarding this page / site http://jordieshapiro.com/home.html

  • How to get input from card reader

    hi, everyone, I have a project, which needs me to get input from card reader. My terminal input is IBM POS system, but it didnot provide the API to get the input. How can I get the input? Need your help so much! and thanks a lot

  • Going to itunes store on xp, it won't go past the window for the advertisement for itunes 10

    When accessing the Itunes store, it loads to the advertisement page of Itunes 10, I don't want to download Itunes 10, but it doesn't give me that option.  I just used the store a few weeks ago.  I don't understand why I can't now.  My operating syste

  • Link to Community in 4.5WS

    I am trying to create a gadget in 4.5WS that provides a list of communities which when the user clicks on the link they are taken to that community. I have tried to follow the guidance given in one of the Plumtree Knowledge base articles which basica