How can I achieve following results with a query

Hello everyone,
I have some data like the following sample and I need to convert it or kind of pivot it
No.      P_1     P_2    P_3
1        1       1       5
1        2       3       1 I want above data to look like the following result set:
P_type  No.   P_values
P_1       1      1,2
P_2       1      1,3
P_3       1      5,1The No. column could go as much as upto 10. Thanks in advance.

Something like:
with t1 as (
            select 1 no,1 p_1,1 p_2,5 p_3 from dual union all
            select 1,2,3,1 from dual
     t2 as (
            select  no,
                    ltrim(sys_connect_by_path(p_1,','),',') p1_values,
                    ltrim(sys_connect_by_path(p_2,','),',') p2_values,
                    ltrim(sys_connect_by_path(p_3,','),',') p3_values
              from  (
                     select  t1.*,
                             row_number() over(partition by no order by 1) rn
                       from  t1
              where connect_by_isleaf = 1
              start with rn = 1
              connect by no = prior no
                     and rn = prior rn + 1
select  'P_1' p_type,
         no,
         p1_values p_values
   from  t2
union all
select  'P_2' p_type,
         no,
         p2_values
   from  t2
union all
select  'P_3' p_type,
         no,
         p3_values
   from  t2
order by no,
         p_type
P_T         NO P_VALUES
P_1          1 2,1
P_2          1 3,1
P_3          1 1,5
SQL> SY.

Similar Messages

  • How can i achieve following results?

    Hi Folks,
    I have data like the following:
    Doc_no       Quantity          Date              Parent_Doc
    G2001             -1000             09/01/2010   
    G2002            -500                10/01/2010 
    G2003            1200               12/01/2010    G2002I would like the results to appear like the following:
    Doc_no                Orig_Qty              New_Qty              Date
    G2001                 -1000                                             09/01/2010
    G2002                 -500                                               10/01/2010
    G2003                 -500                    1200                    12/01/2010Basically if there is a parent_doc number, I want to show the new qty and the old quantity on the same row.
    Thanks,

    dreporter wrote:
    Basically if there is a parent_doc number, I want to show the new qty and the old quantity on the same row.If your hierarchy goes only one level deep, following should give you desired results
    with data as (select 'G2001' as doc_no, -1000 as quantity, to_date('09/01/2000','DD/MM/YYYY') as dt, to_char(null) as parent_doc from dual union all
      select 'G2002', -500, to_date('10/01/2010', 'DD/MM/YYYY'), null from dual union all
      select 'G2003', 1200, to_date('12/01/2010', 'DD/MM/YYYY'), 'G2002' from dual)
    select doc_no, quantity, dt,
           decode(parent_doc, null, quantity, substr(qty, instr(qty, '/', 1)+1, length(qty) - instr(qty, '/', 1, 2))) orig_qty,
           decode(parent_doc, null, null, quantity) new_qty
    from (select doc_no, quantity, parent_doc, substr(sys_connect_by_path(quantity, '/'), 1, 30) qty, dt
            from data
           start with parent_doc is null
           connect by parent_doc = prior doc_no) ;
    DOC_N   QUANTITY DT          ORIG_QTY NEW_QTY
    G2001      -1000 09-JAN-00      -1000
    G2002       -500 10-JAN-10       -500
    G2003       1200 12-JAN-10       -500 1200

  • How can I export the results of a query?

    After executing a select statement I can see the results in a grid but how can I export the results (the data)?
    How can I export the results of a join of two or more tables?

    Right click in the results grid and select the Export menu option

  • How can I share the results with limited access to another user

    I am adding another user to be able to see results of forms submitted, I want the user to add some text into the results view but I don't want him to have access the the design view. How can I make that happen?

    Karina Wiggs
    Director of Operations
    Community Lodgings
    Office: (703) 549-4407
    Cell: (301) 412-4407
    Fax: (703) 548-1294
    Facebook <https://www.facebook.com/Community.Lodgings?ref=tn_tnmn> I
    Twitter  <https://twitter.com/CommunityLdgngs>I Instagram
    <http://instagram.com/communitylodgings>
    www.communitylodgings.org
    On Thu, Dec 4, 2014 at 11:43 AM, Vikrantt Singh <[email protected]>

  • How can I get record count with a query?

    In Client/Server pplication,the client send a query to server.
    How can server get record count by oracle call interface?
    Is it need execute "select count(*) from ...."?

    Yes.
    Either that or increment a counter for each record fetched and
    loop round until you hit the last record.
    The first method would be more efficient on large datasets.

  • How Can I Achieve Collaborative Songwriting with Garageband?

    Hello,
    I don't yet have GarageBand as I'm awaiting my iPhone 6, but I had an idea to do collaborative songwriting with some friends, where I start off with just a beat, and someone else adds bass over the top, and someone else passes that along to another person who adds keys over that, etc.  Obviously, this would be easily achievable by just exporting mp3s, but I'd like to keep the instruments all separate, so I was hoping that GarageBand is "cloud-based" enough to achieve this, where I can share my GarageBand file, if such a thing exists" with others who could add new instruments, change levels of both instruments, etc.
    Is this doable?

    You can upload your songs to iCloud as a GarageBand project from iPone or iPad, but if you want to share it, alarmists would have to use the same AppleID.
    However, If you have a Mac as well, you can download a GarageBand project from iCloud and mail it to another GarageBand user with a Mac. The recipient can save the attached project to iCloud and upload it to the iPad or iPhone.

  • How can i achieve Outerjoin type of results using Reports Datalink option

    Hi,
    i am developing a Oracle Report. i am using Datalink to maintain parent-child relationship between 2 queries. If no matching value found then i want to return 0 Records. how to achieve this.
    Ex: I have 2 tables like Dept & EMP
    DEPT has 2 rows HR and FINANCE
    I have only one employee in HR and no employee in FINANCE.
    I am using the below datalink properties:
    SQL clause : WHERE
    CONDITION ; =
    PARENT GROUP: DEPT
    PARENT Column : DEPTID
    CHILD QUERY : EMP
    CHILD Column : DEPTID.
    In the report it is showing matching columns without any issues> i want non matching columns also with Zero employess like
    HR     1
    FINANCE 0
    I need OUTER JOIN kind of thing. How can i achieve this. Just i have written one example. I have very complex query to implement this and datalink is absolutely necessry for me. Any help please.

    Following can be checked in order to return column value from child Group to Parent Group at data modal.
    a. create a PlaceHolder column ( say CP_1 and CP_2) at parent Group.
    b. create one Formula column at each Child group ( say cf_1 and cf_2 )
    c. write code at formula to return reg_emp as ( say for cf_1)
    srw.reference(:cp_1);
    :cp_1 := :rep_emp;
    for unreg_emp as
    srw.reference(:cp_2);
    :cp_2 := :unreg_emp;
    .. this way now reg_emp and unreg_emp counts can be made available to parent Group.
    To get a difference and return "Yes" or "No" write formula column at Parent Group ..
    Create a Formula column ( say cf_3) at parent group
    write following
    begin
    if :cp_1 = :cp_2 >0 then
    return 'Yes';
    else
    return 'No';
    end if;
    end;
    Now use this formula as source to show value at layout under Parent Repeating Frame.
    Hope this helps..

  • How can I copy test plan WITH ITS RESULTS (PASS/FAIL) to other project in MTM??

    How can I copy test plan WITH ITS RESULTS (PASS/FAIL) to other project in MTM??

    Hi odedn,
    Thank you for posting in MSDN forum.
    Based on your issue, you mean that you want to copy the test plan with test results from the current team project
    to other team project, am I right?
    If yes, as far as I know that when we copy test plan with test results to other team proejcts. It is default that
    there just will not copy the test plan with test results (pass/fail) to other team project in MTM.
    You can refer the following MSDN document’s
    what gets cloned, it explained that which objects are copied from the source test plan to the destination test plan.
    Reference:
    http://msdn.microsoft.com/en-us/library/hh543843.aspx
    If you still want to this feature, I suggest you can
    submit this feature request:
    http://visualstudio.uservoice.com/forums/121579-visual-studio. The Visual Studio product team is listening to user voice there. You can send your idea there and people can vote. If
    you submit this suggestion, I hope you could post that link here, I will help you vote it.
    Thanks for your understanding.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can i plot a histogram with using the results of Line Length

    PLS HELP.How can i prepare a histogram with using the results of line length code(It is somewhere in the middle).
    This is a final exam take-home question. I would appreciate if you can help?
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import java.text.*;
    import java.io.File;
    public class WordAnalyser extends JFrame implements ActionListener
    private JMenuItem jmiAc, jmiSil, jmiCikis, jmiAnaliz, jmiHakkinda, jmiKullanim;
    private JTextArea jta1, jta2;
    private JFileChooser jFileChooser = new JFileChooser();
    File hafizada;
    File aktarilan = new File("Sonuc.txt");
    // Main method
    public static void main(String[] args)
    WordAnalyser frame = new WordAnalyser(); /* Ana ekran olusturulur */
    frame.setSize(400, 300); /* Degerleri belirlenir */
    frame.setVisible(true); /* Gorunebilirligi ayarlanir */
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public WordAnalyser()
    setTitle("Serkan Ozgen Dosya Inceleme Programina Hos Geldiniz");
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);
    JMenu fileMenu = new JMenu("Dosya");
    fileMenu.setMnemonic('F');
    mb.add(fileMenu);
    JMenu helpMenu = new JMenu("Degerlendirme");
    helpMenu.setMnemonic('H');
    mb.add(helpMenu);
    JMenu kullanimMenu = new JMenu("Kullanim Kilavuzu");
    mb.add(kullanimMenu);     
    fileMenu.add(jmiAc = new JMenuItem("Ac", 'A'));
    fileMenu.add(jmiSil = new JMenuItem("Sil", 'S'));
    fileMenu.add(jmiCikis = new JMenuItem("Cikis", 'C'));
    helpMenu.add(jmiAnaliz = new JMenuItem("Analiz", 'D'));
    helpMenu.add(jmiHakkinda = new JMenuItem("Hakkinda", 'H'));
    kullanimMenu.add(jmiKullanim = new JMenuItem("Kullanim"));     
    getContentPane().add(new JScrollPane(jta1 = new JTextArea()), BorderLayout.CENTER);
    getContentPane().add(jta2 = new JTextArea(), BorderLayout.SOUTH);
    jmiAc.addActionListener(this);
    jmiSil.addActionListener(this);
    jmiCikis.addActionListener(this);
    jmiAnaliz.addActionListener(this);
    jmiHakkinda.addActionListener(this);
    jmiKullanim.addActionListener(this);
    public void actionPerformed(ActionEvent e)
    String actionCommand = e.getActionCommand();
    if (e.getSource() instanceof JMenuItem)
    if ("Ac".equals(actionCommand))
    Ac();
    else if ("Sil".equals(actionCommand))
    Sil();
    else if ("Cikis".equals(actionCommand))
    System.exit(0);
    else if ("Analiz".equals(actionCommand))
    sayim();
    else if ("Hakkinda".equals(actionCommand))
    JOptionPane.showMessageDialog(this,
    "!!!! Bu program text analizi gerceklestirir. Her hakki saklidir SERKAN OZGEN!!!!",
    "Bu program hakkinda",
    JOptionPane.INFORMATION_MESSAGE);
    else if ("Kullanim".equals(actionCommand))
         JOptionPane.showMessageDialog(this,
         " Ilk once dosya menusunden Ac i tiklayarak analiz etmek istediginiz Dosyayi seciniz (Lutfen uzantisi *.txt \nveya *.log olsun). Daha sonra Degerlendirme menusunden analizi tiklarsaniz dosyanizda kac adet rakam, harf, \ncumle ve kelime oldugunu gorebilirsiniz. Simdiden kolay gelsin",
         "Programin kullanim detaylari",
         JOptionPane.INFORMATION_MESSAGE);
    private void Ac()
    if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
    hafizada = jFileChooser.getSelectedFile();
    Ac(hafizada);
    // Acilan Dosyayi ana ekranda gostermeye yariyan bir method
    private void Ac(File file)
    try
    // Acilan dosyayi okuma ve ana ekranda gosterme
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
    byte[] b = new byte[in.available()];
    in.read(b, 0, b.length);
    jta1.append(new String(b, 0, b.length));
    in.close();
    catch (IOException ex)
    // Temizle tusunun hangi ekranlara etki edecegini secme
    private void Sil()
    jta1.setText("");
    jta2.setText("");
    private void sayim()
    int buff;
    int sayac = 0;
    int Cumleler = 0;
    int Kelimeler = 0;
    int Karakterler = 0;
    int Satirlar = 0;
    int Rakamlar = 0;     
    boolean start = true;
    int linenum = 0;     
    try
    FileInputStream instream = new FileInputStream(hafizada);
    FileOutputStream outstream = new FileOutputStream(aktarilan);
         BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(hafizada)));
    PrintStream out = new PrintStream(outstream);
         out.println("---Kelime Avcisinin Sonuclari---");
         String line = infile.readLine();
         while (line != null){
         int len = line.length();
         linenum++;
         line = infile.readLine();
         out.println("Line Length :"     + linenum + "\t" +len);
    while ((buff=instream.read()) != -1)
    switch((char)buff)
    case '?': case '.': case '!': /* Eger "?", "." veya "!" gorurse program cumleleri ve kelimeleri arttirir*/
    if (start == false)
    Cumleler++;
    Kelimeler++;
    start = true;
    break;
    case ' ': case '\t': case ',': case ';': case ':': case'\"': case'\'': /* Eger /t,;:\ ve \" bu isarteleri goruruse program kelimeleri arttirir */
    if (start == false)
    Kelimeler++;
    start = true;
    break;
              case 'n': case '\n': /* Eger \n gorurse satirlari arttirir */
              if (start == false)
                   Satirlar++;
                   Kelimeler++;
                   start = true;
              break;
    default:
    if (((char)buff >= 'a' && (char)buff<='z')|| /*a-z, A-Z veya - degerlerini gorurse karakterler arttirilir */
    ((char)buff >= 'A' && (char)buff<='Z')||
    ((char)buff == '-'))
    Karakterler++;
    if ((Kelimeler % 50) == 49)
    if (start == true)
                   out.println();     
    out.print((Kelimeler+1) + " ");
    out.print((char)buff);
    start = false;
              if ((char)buff >='0' && (char)buff <='9') {  /* 0-9 gorurse rakamlari arttiri */
                   Rakamlar++; }
    }// switch
         }//while
    instream.close();
    out.println();
    out.println();
    out.println("Karakter sayisi: " + Karakterler);
         out.println("Kelime sayisi: " + Kelimeler);
    out.println("Cumle sayisi: " + Cumleler);
         out.println("Satir sayisi: "+ Satirlar);
         out.println("Rakam sayisi: "+ Rakamlar);
    outstream.close();
    try
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(aktarilan));
    byte[] b = new byte[in.available()];
    in.read(b, 0, b.length);
    jta2.append(new String(b, 0, b.length));
    in.close();
    catch (IOException ex)
    catch (Exception e)
    System.out.println(e);
    }

    Why is it that you're not interested in IOExceptions?
    catch (IOException ex)
    } Empty catch blocks is a hallmark of foolish Java code. At least print out the stack trace.
    %

  • How can I replace column value with a particular value in SQL

    Hi All,
    Can anyone please tell me how can I format my output with replacing a column value with a specific value which actually depends on the present value of the column
    I am executing the following SQL statement
    select state,count(id) from <table_name> where composite_dn= <composite_dn_name> group by state;
    My Present output is:
    State No.Of Instance
    1 3
    3 28
    I want to replace the value in the column state as follows
    State No.OfInstances
    Completed 3
    Faulted 28
    I want "1" to be reppaced by "Completed" and "3" to be replaced by "Faulted"
    Is is possible with SQL or PL/SQL , if it is then how can I achieve this required result. Please help!!
    Thanks in Advance!!
    Edited by: Roshni Shankar on Oct 27, 2012 12:38 AM

    Hi Roshni,
    I guess this CASE clause can be simulated by a DECODE and also it is very easy to use.
    Refer -- http://www.techonthenet.com/oracle/functions/decode.php
    select decode(t1.state,t2.state_id,t2.state_name), t1.count_id
    from <table_2> t2, (select state,count(id) count_id
    from <table_name>
    where composite_dn= <composite_dn_name>
    group by state) t1
    where t1.state = t2.state_id;HTH
    Ranit B.
    Edited by: ranit B on Oct 27, 2012 2:02 PM
    -- link added
    Edited by: ranit B on Oct 27, 2012 2:19 PM
    -- sample code added

  • How can I do something similar with Lightroom

    With the combination of the Editor of "Photoshop Elements" (PSE) and of the KODAK SHO Professional Plugin (which runs as a "filter"-plugin in the PSE Editor environment), I can often fixd photos which-
    - have both bright and dark portions
    - and which show poorly details in the bright portions.
    But (probablay because I have not sufficient LR expertise), I do not understand how to achieve similar results (or: better results) with Lightroom.
    Is an experienced LR user aware of a relatively ***simple*** way to achieve something similar (or, even  to achieve better results) with LR and is willing to explain her/his solution to me? Thanks very much in advance for it.
    Now, I need to explain in detail, with one concrete example, what I can do with the combination of PSE and KODAK SHO.
    A concrete example of a Photo that I need to edit follows (continuation of the description of my problem/questions follows in the next Post).

    The Fill Light slider brings the shadows up and the Recovery slider brings the highlights down.
    Also, in LR3 the Curves is different from LR 2 in  so far as you now can pull up or down both ends of the curve vertically. This was not possible in LR 2.
    Grab the little circle at the left / bottom end of the curve and pull it up vertically. That will lighten your blacks / shadows. Grab the little circle at the right / top end of the curve tool and pull it down. That will darken your highlights. This process will make your image look a bit flat; if so, increase contrast by giving the curve a gentle S-form.
    Directly below the curves tool you have the option to choose between "linear', "medium contrast', or "strong contrast'. If you choose one of the latter two, the end points of the curve will snap back to zero but the curve will have a curve (no pun).
    Also, in case your image does not have enough contrast, instead of using the contrast slider, you can pull the end points of the curve horizontally.
    Apart from these image-wide changes you can make local changes with the adjustment brush or with graduated filter. I often use the gard filter to give a little "ooomph" to the sky by setting exposure (for the grad filter) to -0.66. Similarly you can lighten the shadows with a grad filter by giving it an + exposure and/or increasing brightness. Make sure that the grad filter doesn't give you a color toning - unless you want it. With a color toning you can make your shadows less blue (by choosing yellow toning) and your sky more blue (by choosing a blue toning). Naturally you'd need 2 different grad filters for that; you can't have 2 different settings in one grad filter.
    ErnstK

  • I have a large number of photos imported into iPhoto with the dates wrong.  How can I adjust multiple photos (with varying dates) to the same, correct, date?

    I have a large number of photos imported into iPhoto with the dates wrong.  How can I adjust multiple photos (with varying dates) to the same, correct, date?

    If I understand you correctly, when you enter a date in the Adjust Date and Time window, the picture does not update with the date you enter.  If that is the case then something is wrong with iPhoto or your perhaps your library.
    How large a date change are you putting in?  iPhoto currently has an issue with date changes beyond about 60 years at a time.  If the difference between the current date on the image and the date you are entering is beyond that range that may explain why this is not working.
    If that is not the case:
    Remove the following to the trash and restart the computer and try again:
    Home > Library > Caches > com.apple.iphoto
    Home > Library > Preferences > com.apple.iPhoto (There may be more than one. Remove them all.)
    ---NOTE: to get to the "home > library" hold down option on the keyboard and click on "Go" > "Library" while in the Finder.
    Let me know the results.

  • How can i display the result of java class in InputText ?

    Hi all,
    How can i get the result of java class to InputText Or OutputText ???
    also can every one in the forum give me road map for dealing with java in oracle adf because i'm beginner in oracle adf
    i saw some samples in oracle adf corner but it's difficult for me.

    User,
    Always mention your JDev version, technologies used and clear usecase description (read through this announcement : https://forums.oracle.com/forums/ann.jspa?annID=56)
    How can i get the result of java class to InputText Or OutputText ???Can you elaborate on your requirement? Do you mean the return value of a method in a class as output text? Or an attribute in your class (bean?) as text field?
    -Arun

  • How can i achieve tis in Bex Query Designer

    Hi Experts,
    Please advise on how can i achieve this in Query.
    I got Location,Material_ID,Price and Change_Date.
    (Change_Date is defined as both CHAR & KF in cube)
    (Change date is on monthly basis they execute a programe in non sap source system to update the prices of material)
    The Price of material tends to change or may not change ...
    Every month we get a record from source system on material price
    My requirment is to bulid a report that show
    LocationMaterial_IDCurrent Price  and Previous Price
    Please advise how can i develop this report

    While loading into cube, normally you map  price field coming from datasaource to
    infobject  ZPRICE_CURRENT   in your infocube.
    So in transformation you map like this
    price  -
    > ZPRICE_CURRENT
    Now, Maintain another keyfigure in cube  ZPRICE_PREVIOUS.
    That is not mapped with anything.But is assigned a value in the Start routine
    which just runs before, the transformation.
    In the start routine write code something like this :
    Read current value of price from cube for that Material.
    (Select  ZPRICE_CURRENT into price_curr  from cube where material = DATA-PACKAGE- Material   )
    if  DATA_PACKAGE-price <> price_curr   ( if new_price <> old_price)
    ZPRICE_PREVIOUS = price_curr. (storign present value of price in the cube )
    endif.
    Now save the Start routine. When mapping the fields in the transformation
    dont map anythign to  ZPRICE_PREVIOUS as it is already filled in teh start routine from the above  code.Leave it unmapped.
    The below mapping is normally maintained without change..
    price  -
    > ZPRICE_CURRENT
    If you find this to be useful ..please do the needful (points)

  • How can i display my portal  with a certain language in the runtime

    I am imp[lemeting a portal page
    their will be a language choice  English   -   French  - Arabic
    I want the portal page to be displayed in the Arabic if the user choose Arabic
    I want the portal page to be displayed in the French if the user choose French
    I want the portal page to be displayed in the Englis if the user choose English
    How can i achieve that target
    Regards
    Mohamed Hammed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sandeep
    How can i "Set Language" Portlet
    My portal page contains
    many portlets
    many items
    many subpage links
    i want all of this to function with the chosen language
    Regards
    Mohamed Hammed

Maybe you are looking for