Is there an easier/simpler way of obtaining this result ?

Good morning (afternoon to you, BluShadow),
I obtained the following correct, as desired, output (derived from the EMP table):
D10     D20     D30     PREZ    MGRS    ANALS   SALESM  CLERKS
CLARK   JONES   WARD    KING    BLAKE   FORD    ALLEN   ADAMS
KING    FORD    TURNER          CLARK   SCOTT   MARTIN  JAMES
MILLER  ADAMS   ALLEN           JONES           TURNER  MILLER
        SMITH   JAMES                           WARD    SMITH
        SCOTT   BLAKE
                MARTINusing the following query:
with
   -- pivoted departments  (haven't studied the Oracle PIVOT clause yet)
   depts as
    select max(case deptno
                 when 10 then ename
               end)                                 as d10,
           max(case deptno
                 when 20 then ename
               end)                                 as d20,
           max(case deptno
                 when 30 then ename
               end)                                 as d30,
           rnd
      from (
            select deptno,
                   ename,
                   row_number() over (partition by deptno
                                          order by deptno)  rnd
              from emp
     group by rnd
     order by rnd
   -- pivoted jobs
   jobs as
    select max(case job
                 when 'CLERK'         then ename
               end)                                 as Clerks,
           max(case job
                 when 'PRESIDENT'     then ename
               end)                                 as Prez,
           max(case job
                 when 'MANAGER'       then ename
               end)                                 as Mgrs,
           max(case job
                 when 'ANALYST'       then ename
               end)                                 as Anals,
           max(case job
                 when 'SALESMAN'      then ename
               end)                                 as SalesM,
           rnj
      from (
            select job,
                   ename,
                   row_number() over (partition by job
                                          order by ename)   as rnj
              from emp
     group by rnj
     order by rnj
select d10,
       d20,
       d30,
       Prez,
       Mgrs,
       Anals,
       SalesM,
       Clerks
  from depts a full outer join jobs b
                            on a.rnd = b.rnj
order by rnj, rnd;which takes a total of 5 selects to get there.
I was trying to find a query that would be, hopefully simpler, easier and didn't require as many selects. My last attempt is the following (which is close to the desired result but doesn't get a cigar yet):
select case deptno
         when 10 then ename
       end                                 as d10,
       case deptno
         when 20 then ename
       end                                 as d20,
       case deptno
         when 30 then ename
       end                                 as d30,
       case job
         when 'CLERK'         then ename
       end                                 as Clerks,
       case job
         when 'PRESIDENT'     then ename
       end                                 as Prez,
       case job
         when 'MANAGER'       then ename
       end                                 as Mgrs,
       case job
         when 'ANALYST'       then ename
       end                                 as Anals,
       case job
         when 'SALESMAN'      then ename
       end                                 as SalesM,
       row_number() over (partition by deptno
                              order by deptno)  as rnd,
       row_number() over (partition by job
                              order by ename)   as rnj
  from emp
order by rnj;The above query gets me to this result which is encouraging but... short of the mark:
D10     D20     D30     CLERKS  PREZ    MGRS    ANALS   SALESM   RND  RNJ
                ALLEN                                   ALLEN      3    1
        ADAMS           ADAMS                                      2    1
                BLAKE                   BLAKE                      6    1
KING                            KING                               2    1
        FORD                                    FORD               1    1
        SCOTT                                   SCOTT              5    2
                JAMES   JAMES                                      5    2
CLARK                                   CLARK                      3    2
                MARTIN                                  MARTIN     2    2
                TURNER                                  TURNER     1    3
MILLER                  MILLER                                     1    3
D10     D20     D30     CLERKS  PREZ    MGRS    ANALS   SALESM   RND  RNJ
        JONES                           JONES                      3    3
                WARD                                    WARD       4    4
        SMITH           SMITH                                      4    4It uses only one SELECT statement and has all the data that needs to be displayed but, I cannot find a way of eliminating the nulls without losing either some jobs or some depts.
Your help is welcome and appreciated,
John.
PS: I'll be perfectly happy learning that there is no easier/simpler way. In other words, if the answer is simply "No, there is no simpler/easier way", please do let me know that is the case. (I ask that you be fairly sure of that though, thank you)
Edited by: 440bx - 11gR2 on Jul 25, 2010 7:19 AM - Added PS.

Hi, John,
You had part of the solution in each of your attempts.
Do a FULL OUTER JOIN, as in your first query, on two copies of the result set of your second query.
Using Oracle 9 features only:
WITH     got_row_numbers     AS
     select     case WHEN deptno = 10 then ename end               as d10,
                 case WHEN deptno = 20 then ename end                    as d20,
                 case WHEN deptno = 30 then ename end                    as d30,
                 case WHEN job = 'CLERK'     then ename       end        as Clerks,
                 case WHEN job = 'PRESIDENT' then ename       end        as Prez,
                 case WHEN job = 'MANAGER'   then ename       end        as Mgrs,
                 case WHEN job = 'ANALYST'   then ename       end        as Anals,
                 case WHEN job = 'SALESMAN'  then ename       end        as SalesM,
                 row_number () over ( partition by      deptno
                                        order by           NULL
                       )                           as rnd,
                 row_number () over ( partition by      job
                                        order by           ename
                       )                            as rnj
  from      emp
SELECT       MIN (d.d10)          AS d10
,        MIN (d.d20)          AS d20
,       MIN (d.d30)          AS d30
,       MIN (j.clerks)     AS clerks
,       MIN (j.prez)          AS prez
,       MIN (j.mgrs)          AS mgrs
,       MIN (j.anals)          AS anals
-- ,        MIN (j.salesm)     AS salesm
FROM            got_row_numbers     d
FULL OUTER JOIN     got_row_numbers     j     ON     d.rnd     = j.rnj
GROUP BY  NVL (d.rnd, j.rnj)
ORDER BY  NVL (d.rnd, j.rnj)
;I've been trying to think of a good name for this kind of query where the items one the n-th row have nothing in common except that they are on the n-th row. For lack of anything better, I call it a Prix Fixe Query , because it resembles the menus where, for a fixed price, yuu can choose different options for each course:
Appetizer     Soup          Main Course     Desert
Pakora          Coconut          Aloo Gobi     Galabjamun
Salad          Lentil          Bharta          Halwa
Samosa                    Dhosa          Kulfi
                    Saag PaneerAbove, each column is sorted alphabeticlly. There is nothing but pure coincidence linking 'Pakora' with 'Coconut' or "Aloo Ghobi' with 'Galabjamun': they just happen the be the first items, in alphabetic order, in their respective columns.
You may notice that I used
"PARTITION BY deptno ORDER BY NULL " where you used
"PARTITION BY deptno ORDER BY deptno "
It never makes sense to ORDER BY anything in the PARTITION BY list. Each distinct item in the PARTITION BY list is a world of its own. You will only sort things that are identical with respect to the PARTITION BY list. That is, if the system has to decide whether to give 'CLARK' or 'KING' the lower ROW_NUMBER in deptno=10, deptno itself will not help the decision: the deptno for both will necessarily be the same. There's no syntax error, it just doesn't do any good, and the order of the output will be arbitrary.
There would be a syntax error if you omitted the ORDER BY clause: ROW_NUMBER must be done in the context of some ordering. If you really want the order to be arbitrary, then be clear about it. ORDER BY a constant (such as NULL) so that nobody reading the query quickly is fooled into thinking you really are ordering by something. (A comment would be helpful in that case, also.)
You probably want to "ORDER BY ename", or something meaningful, in this case.
Edited by: Frank Kulash on Jul 25, 2010 2:41 PM
Added digression of "PARTITION BY x ORDER BY x"

Similar Messages

  • Is there any easy & simple way to set specify font to all text

    Is there any way to set a specific font to all text of Swing controls (JLabel, JButton, etc)? And their font's style (bold, underscore...) and font's size still remain to their customized settings.
    Thanks in advance.
    null

    perhaps you're just after deriveFont()
    run this, you'll see both fonts the same
    import javax.swing.*;
    import java.awt.*;
    class Testing
      public void buildGUI()
        JLabel label_1 = new JLabel("Hello");
        JLabel label_2 = new JLabel("World");
        label_1.setFont(new Font("monospaced",Font.BOLD|Font.ITALIC,12));
        label_2.setFont(label_1.getFont());
        //label_1.setFont(label_1.getFont().deriveFont(36f));//<----------
        JFrame f = new JFrame();
        f.getContentPane().add(label_1,BorderLayout.NORTH);
        f.getContentPane().add(label_2,BorderLayout.SOUTH);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }now uncomment the indicated line, recompile/rerun
    you'll see the style remains, but the size increased

  • Syncing an iPhone 4s with a Droid razr M - is there any relatively simple way to do this?

    My wife has a 4s and our computer is a MacBook Pro.  Is it possible for me to have an Android phone (the new Razr M) and to somehow have it be compatible with those Aplle devices in our household?  I like the 4s, but am concerned its technology won't be able to keep up with the changes that are likely to occur before the end of my next 2 year Verizon contract.
    So, should I get a Razr M and try to make it compatible or should I just get a 4s?  (BTW - an iPhone 5 isn't in our budget right now)
    Thanks.

    Only your service provider can unlock the phone. Check with the provided.

  • Output_link is there any easier (shorter) way??

    Is there any easier (shorter) way to create an simple link as the code below? I am wondering that the code for creating an simple link moved from one line
    <h:command_hyperlink href="login.jsp" label="Login Page"/>
    To 4 lines:
    <h:output_link value="login.jsf">
    <f:verbatim>Login Page</f:verbatim>
    </h:output_link>

    AFAIK, there's not an easier way in the beta. I'll pass this on to the rest of the EG.
    Regards,
    Adam Winer (EG member)

  • I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?

    There is currently no way to merge accounts.  The best option is to pick one, and use it consistantly.
    HTH.

  • Is there a (relatively simple) way to skip tracks with an iPod touch 5th gen using a physical button? I'm aware songs can be skipped on-screen without unlocking the iPod, but I'm looking for a method that doesn't require taking my eyes off the road.

    Is there a (relatively simple) way to skip tracks with an iPod touch 5th gen using a physical button? I'm aware songs can be skipped on-screen without unlocking the iPod, but I'm looking for a method that doesn't require taking my eyes off the road while driving. For that reason, I'm also not interested in adding in headphones or additional devices that have the desired button functions. Going both forward and back would be great but I would be pleased just to have a "sight-free" way to go forward.
    I've seen some mention here and there about ways to maybe change it so the volume buttons change tracks and holding the volume buttons changes the volume... but I don't know what's involved in that or if its even possible/recommended for a new 5th gen iPod. I think its a great device but its sadly lacking in music oriented functions and features... which is disappointing since music is why most people would bother getting one instead of some other "iDevice" :/

    Given that you cannot do what you have asked for, perhaps you simply need to find another solution to your root problem.
    Presumably, you want to skip to the next track because you don't want to hear the current one, and that is because...
    You don't like it.
    You've heard it recently and don't want to hear it now.
    Simply don't want to hear it at this time.
    For problem number 1. Don't put it on the iPod in the first place. (I know, obvious answer!)
    For problem number 2. How about playing from a Smart Playlist (initially created in your iTunes Library) which has only songs you've not played recently?
    For problem number 3. Hhhmmm! Create alternative Playlists for use in the car.
    As for going back to the start of the "now playing" track.... Well, if your Playlist has only songs that you really, really want to hear, then you'll be looking forward to that rather go back to the beginning of the current song.
    I'm not trying to be prescriptive, just giving you food for thought.
    (They are all cheaper options than buying a car which can control the iPod from the steering wheel.)

  • How do I sync music onto old iPod when my music is on iTunes match? I have connected the iPod to my mac but it indicates no music to sink (as my music is in the cloud). I assume there is a simple way to resolve without downloading all music onto my mac?

    How do I sync my music onto an old iPod when my music is located on iTunes match? I have connected the iPod to my mac but it indicates no music to sink (as my music is stored in the cloud). I assume there is a simple way to resolve without downloading all music onto my mac as this would be ridiculous?
    Any halp with this would be excellant.
    Thanks :P

    Hi,
    Your old pod can only sync with music that is physically in your itunes library and on your hard drive. Therefore there is simple way to resolve is to download your music to your hard drive.
    Jim

  • Whether there is a simple way to add new Mapping operators on a mapping?

    Whether there is a simple way to add new Mapping operators on existing mapping?
    For example I have a mapping, but now I need to add new Filter or Aggregator operator, so I must delete all connections between attributes, then add new operator, connect source attributes to the input attribute for the operator and so on.
    Is there way to turn down this operations, simply drop new operator on source object or on a connection between two objects, and necessary operations will be automatically executed.
    As I remember in OWB2 something similar existed in a way to add new Filter operator.

    Dmitry,
    Unfortunately there is not. What you should aim for, is to use the group-by-group mapping using match by name (with some additional options, such as ignore source/target prefix, suffix, etc.).
    I.e. if you want to insert another operator, then I recommend you first populate attributes based on an operator that is currently on the mapping delete the old operator (to delete all connections), map into the new operator and add another operator in order to re-create what you previously had. I know it is not ideal... but in my experience it is the most productive way to work.
    Thanks,
    Mark.

  • Just bought a new MacBook Pro. Would like to transfer my Waves plugins from My old Hard Drive into my new MBP. IS there s simple way to do this?

    Just bought a new MacBook Pro. Would like to transfer my Waves plugins from My old Hard Drive into my new MBP. Is there a simple way to do this?

    Hi
    The easiest and most reliable way would be to download the installer from Waves and re-install.
    CCT

  • I've created a prproj file and want to create a master DVD.  Is there a simple way to do this?

    I've created a prproj file and want to create a master DVD. Is there a simple way to do this?

    I'm not sure I would call disk authoring a 'simple' process.  Unless it's a very basic disk, or course, with but a single timeline and no menus.  But the kind of disk we're using to seeing from Hollywood is anything but simple to create, and so not so simple to explain.
    Might be time for some research.

  • I want to move syncing my iphone from one computer to another. (windows based) Is there a one stop way to do this?

    I want to move syncing my iphone from one computer to another. (windows based) Is there a one stop way to do this?
    Thanks

    Copy everything from one computer to the other then sync.

  • I've found no way to sort.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results.

    I've found no way to sort search results in itunes.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results. 

    In the Search box click on the black Arrow and UNTICK the Search Entire Library.
    Then the Search results in Songs view will be displayed in the main Grid and you can sort them by clicking on the column headers.
    You can also turn on the column browser which can help with filtering

  • I have a small production client looking to run 1 workstation running Mac Lion 10.7.3 and two work stations running Windows7 64 bit. They will all be talking to the same storage array through 8Gb FC. What is there most cost effective way to do this?

    I have a small production client looking to run 1 workstation running Mac Lion 10.7.3 and two work stations running Windows7 64 bit. They will all be talking to the same storage array through 8Gb FC. What is there most cost effective way to do this?

    Thank you for your help.
    The client has already made the jump to 8Gb including HBA's, switch and RAID Storage.
    The other question will be if they need a seperate Mac Server to run the Meta Data or are they able to use the current Mac they are running to do this?
    The Mac is a 201073 model they say with 12 Dual Core 2.66Mhz processors and 16 GB of Memory. This system is currently doing rendering. It has the XSAN Client but I understand for the solution to work they need to also run XSAN Server on a MDC.

  • After sharing a folder of images with someone, is there an easy/fast way to view the images with comments?

    I shared a folder of 100 images with a friend.  She commented on the images she would like edited.  Is there an easier way to view the photos she commented on, other than clicking on each image to view the activity? 
    Thank you!

    You will likely get better program help in a program forum (maybe Photoshop?)
    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • I want to display all errors in a listbox. Is there a simple way to do this, such as a vi that takes as input: error_in, error_out, listbox and then appends the error text to the listbox if the error_out is different than error_in?

    would like to display time of occurrence and error text, so possibly a table instead of a listbox

    You can check on the alliance page for a product that does this, but there are no LabVIEW utilities to do this specific task. You will have to build one yourself it seems.

Maybe you are looking for

  • Sine generator VI output jump

    Hi, I was describing a problem in the Multifunction DAQ board, but it looked like software had a part to play too. Basically, I was running a sine generator VI through analog output to a speaker, and experienced a sudden break or phase skip in the ou

  • Mac Mini will not load after recent update.

    My late 2012 model Mac Mini just had a software update and upon rebooting, my login name did not populate.  I rebooted again and now I get the gray screen with spinner and progress bar.  Once the progress bar loads I have just the spinner for a minut

  • Unable to extend lob segment SAPSR4DB

    Hi All, I am getting the error u201Cunable to extend lob segment SAPSR4DBu201D when i try to import any dependency into my SC or during the Assembly of my SCA. Then we go and increase the space of the table, it starts working. I would like to know ho

  • Audio Export option for Quicktime

    Finishing a 1 hr doc for broadcast. The sound designer gave me a 2 stereo stems, one music and one dialogue. Each stem has a left and right channel (-1,1). All soundws good and balanced. My question is, I'm exporting a master quicktime to send to the

  • System not shutting down

    i am having solaris 9. when i try to shutdown my machine using [root@xyz][-202] shutdown -i0 -g0 -y it just shows the prompt [root@xyz][-203] but does not shutdown. any suggestions will be welcome.