Is there a more easy/more simple way to achieve this?

Good morning (afternoon to you, BluShadow).

I got following exact, as you wish, 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
                MARTIN
by using 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;
that takes a total of 5 selects to get there.

I tried to find a query that would be, I hope more simple, easier and does not require as much selects. My last attempt is the following (which is closer to the desired result, but does not 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 query above annoys me to this result which is encouraging, but... the brand:
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    4
It uses a single SELECT statement and contains all the data that should be displayed, but I can't find a way to eliminate NULL values without losing a few jobs or departments

Your help is welcome and appreciated,

John.

PS: I'll be perfectly happy to learn that there is no way more easy/simple. In other words, if the answer is simply "No, there no simpler or easier way", please let me know which is the case. (I ask that you be sure enough of that though, thank you)

Published by: 440bx - 11 GR 2 on July 25, 2010 07:19 - added PS.

According to the hoek' suggestion ;-)

SQL> select d10, d20, d30, prez, mgrs, anals, salesm, clerks
  2    from (select row_number() over(partition by deptno order by ename) rn,
  3                 ename,
  4                 to_char(deptno) deptno
  5            from emp
  6          union all
  7          select row_number() over(partition by job order by ename),
  8                 ename,
  9                 job
 10            from emp) pivot(max(ename) for deptno in(10  d10,
 11                                                     20  d20,
 12                                                     30  d30,
 13                                                     'ANALYST'  anals,
 14                                                     'CLERK'  clerks,
 15                                                     'MANAGER'  mgrs,
 16                                                     'PRESIDENT'  prez,
 17                                                     'SALESMAN'  salesm))
 18   order by rn
 19  /

D10        D20        D30        PREZ       MGRS       ANALS      SALESM     CLERKS
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
CLARK      ADAMS      ALLEN      KING       BLAKE      FORD       ALLEN      ADAMS
KING       FORD       BLAKE                 CLARK      SCOTT      MARTIN     JAMES
MILLER     JONES      JAMES                 JONES                 TURNER     MILLER
           SCOTT      MARTIN                                      WARD       SMITH
           SMITH      TURNER
                      WARD

6 rows selected.

Best regards

Maxim

Tags: Database

Similar Questions

  • Is there a more effective way to interrogate this cache?

    I have an interesting dilemma that I don't know how to fix. I have a cache of objects ClientType (see below). I'm trying to find the CustomerGroups that contain a password key for the customerValues card, which also have a CustomerValue.value between a high and low value. In others, do me all the CustomerGroups who have a client of "101" code, which contains a CustomerValue between 50 and 250. I have this fine work to aid request a customer filter - but the problem I have is that the cache contains approximately 500,000 items. The research must be applied to all objects, and because most of the clients contain a customervalue - we end up deserialization of objects to perform the comparison of the value in the cache that fills the eden space so quickly (in a multi-threaded env) that we are to throw himself into the holder space. This causes performance issues because it weakens the large global catalogs. We use 3.5.2 consistency and all are active POF. The works of current query - I'm looking for the most effective way to do with respect to the use of time and lot. I am willing to trade increased Rightsizing memory use for best performance - which means the addition of index / improves the news is very good. The big problem is fill the eden space so quickly. Any ideas?
    class CustomerGroup
    {
        Set<Customer> customers ;
    }
     
    class Customer
    {
        Map<Integer, CustumerValue> customerValues;
    }
    
    class CustomerValue
    {
      private int value ;
      private boolean isNew ;
    }

    Simi74 wrote:
    Robert - appreciate the help. The question I have for this juicer is that the price is related to a specific customer. For example:

    ClientType contains 1 client.

    This customer has 2 CustomerValues in his card.

    These entries to resemble the following:

    Key: 100
    Value: CustomerValue.value = 10
    
    Key: 200
    Value: CustomerValue.value = 50
    

    If I'm following your logic, the extractor that you recommended would apply to values (that is to say, 10, and 50). So, if I searched for CustomerGroups that have values between 5 and 15,
    return the ClientType as one of the values is 10. However, I also this map to a specific client code (in this case either 100 or 200 - they key in the matching values). Thus, the query is really more like 'give me all the objects ClientType to 100 client code where the value is between 5 and 15'. I should only get this object if the client code is 100. I can't do a ContainsFilter with the client code and use BetweenFilter because using an AllFilter since this logic would be tantamount to a 'false' positive press 200. Logical in this case being 'the ClientType contains a 200 client' who is true and does the ClientType contain a value between 5 and 15, which is also true, because the value list has 10 and 50. But it must return this object ONLY if the customer key passed is 100. The example below is a false positive.

    /* following code returns the object, but should not! */
    Filter[] filterArray = { new ContainsFilter( new CustomerKeyExtractor(), new Integer( 200 ) ),
    new BetweenFilter( new CustomerValueExtractor(), 5, 15) };
    
    Filter filter = new AllFilter( filterArray ) ; 
    

    So my question is how to apply a hint on the CustomerKey/CustomerValue as a whole without deserialize all the objects for each search? Or is it a problem with the structuring of the object? If that's the problem - of recommendations on alterations are welcome as well fix this filtering.

    Ah, ok, got it now...

    What is the client code?

    Is it just a key generated with an arbitrary value, or is it a thing of enum type (key to a value of metadata property with only a finite number of different property names, etc.) with only a small number of different codes in all of the cache?

    If it's a thing of enum type, then instead to extract only the 'value' s as integers, you can extract pairs ' value: code "represented as long with the code being the high 32 bit which would be always classifiable and allow querying: instead of valueMin and valueMax, you would code: valueMin and code: valueMax as the beach.

    If it's an arbitrary generated value, then it is a bit more problematic (extraction POF does not support crossed down in individual map entries, so it can't be indexed without the plan, including the entire Customer objects to deserialize), but I wouldn't address that if it is not necessary, so please indicate if the previous approach fits your needs :). In the case that it is not, you would probably want to the extracted value to be structured on the other hand, the value is the code and 32-bit higher at least 32. You must also write a custom filter that supports the index which is able to use this index going in the direction of Alexey BetweenFilter but with additional controls for the code... In addition, you must check whether the consumption of memory of the filter can be too high...

    Best regards

    Robert

  • You want to animate a vector line on the edge - a simple way to achieve this?

    I have a logo I want to animate on the edge of a Web site.

    Its a line chart & I want to achieve the "hand-drawn" animation style for the header of the first page of a Web site.

    Y at - there no easy way to go about it - I can't find anything online! I'm using the wrong program?

    lulu_line_graphic.PNG

    Thank you

    You can use the Web to do.

  • Is there a part in a simple way a project among the developers?

    There are three developers in our shop.  We will all work on the same Flex project simultaneously.   Is there a part in a simple way a project among the developers?  We currently use Dreamweaver for our ColdFusion code and as Check-in/out service.  I don't see any similar functionality in Flex.  I read the content of help on CVS, but it seems exaggerated.  In addition, I have no idea how set up.  Any recommendations?

    I would recommend learn from Subversion (which is a bit like CVS, only a bit more modern): http://subversion.tigris.org

    There is a plugin for Flex Builder (Eclipse) that makes use of Subversion is quite easy: http://subclipse.tigris.org

    There is definitely a learning curve to set up and use a full source control system like Subversion.  But well worth the effort (and some would say an absolute necessity).  You can also find suppliers of Subversion hosted, which could reduce your preparation time.  Take the plunge.

    Let me know if you have any other questions...

    Ben Edwards

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

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

    You need to export an MPEG2-DVD file for use in an application to create DVD (like Encore CS6)

    You can also create an ISO for mastering purposes image file.

  • Can you help me? Is there a simpler way to write this short code?

    Hi, I'm quite new to coding and EDGE and think there must be a simpler way to write this? :

    sym.getSymbol("USA_animation").play ();

    sym.getSymbol("World_map").play ();

    sym.getComposition () .getStage ().getSymbol("UK_animation").$("UK").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("UK_animation").$("Piechart").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("UK_animation").$("people").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("UK_animation").$("PeopleText").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("UK_animation").$("UKText").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("AUS_animation").$("AUSTRALIA").fadeOut ();

    sym.getComposition () .getStage ().getSymbol("USA_animation").$("USA").show ();

    sym.getComposition () .getStage ().getSymbol("USA_animation").$("USAText").show ();

    Can you help me?

    Obivious to increase efficiency is

    var USA_animation = sym.getSymbol ("USA_animation")

    USA_animation. Play();

    sym.getSymbol("World_map").play ();

    USA_animation.$("UK").fadeout ();

    USA_animation.$("PieChart").fadeout ();

    USA_animation.$("people"). fadeOut();

    USA_animation.$("PeopleText").fadeout ();

    USA_animation.$("UKText").fadeout ();

    USA_animation.$("AUSTRALI_A").fadeout ();

    USA_animation.$("USA"). Show();

    USA_animation.$("USAText"). Show();

    If you perform a single operation on all the symbols of the "USA_animation" child, you can also reduce somethinng as

    sym.getSymbol("World_map").play ();

    var USA_animation = sym.getSymbol ("USA_animation")

    USA_animation. Play();

    var childSymbols = USA_animation.getChildSymbols (); f

    for (var i = 0; i)

    childSymbols [i] .fadeOut ();

    I don't know if these are the best ways, but these are in a way that I could think of.

    Let us know if offer you a lot shorted way to write this

  • I'm moving my files to workspaces to cloud.adobe.  What is the best way to achieve this?

    I'm moving my files to workspaces to cloud.adobe.  What is the best way to achieve this?

    Hi Traci,

    So big that you get ready for the transition to cloud.acrobat.com! Please see that the specified item was not found. For more detailed information on downloading your files.

    When you open a session workspaces, however, you will see a big red box at the bottom left. Click this box, and your files will be packed to the top for you. You will receive an email with the instructions when the packaged files are ready for you.

    Best,

    Sara

  • With the help of the meter from 6525 to measure the frequency: is there a more orderly way?

    I am currently using the high speed on a module USB 6525 meter to measure the frequency of an object in rotation via a sensor hall-effect.

    I was wondering if there was a simpler way / more effective this encoding than that?

    Everything that I currently perform the current meter reading, wait a second, take another reading, and subtract one from the other. The result is the frequency in hertz.

    Is there a way to get the 6525 to return the number / change County after 1 second?

    Thank you

    On the 6525, you have a country of the event and you can't make a measure of frequency.

  • Is there a more efficient way to use the visible property node to make the inactive/hiding controls on the front?

    I just inherited the labview code to run a system of imaging optics mamography.

    It has 32 sources 128 detectors and 2 games of light and the user has the possibility to control the parameters of gain for each sensor to each source for each source of wavelengths, so as you can imagine there are a lot of orders and LEDs on the front panel.

    The user also has the possibility to choose the number of sources and that they would like to use detectors.  v: * {behavior:url(#default#VML) ;} O'Bryan: * {behavior:url(#default#VML) ;} w\: * {behavior:url(#default#VML) ;} .shape {behavior:url(#default#VML) ;}}}} Normal 0 false false false MicrosoftInternetExplorer4 / * Style Definitions * / table. MsoNormalTable {mso-style-name: "Table Normal" "; mso-knew-rowband-size: 0; mso-knew-colband-size: 0; mso-style - noshow:yes; mso-style-parent:" ";" mso-padding-alt: 0 to 5.4pt 0 to 5.4pt; mso-para-margin: 0; mso-para-margin-bottom: .0001pt; mso-pagination: widow-orphan; do-size: 10.0pt; do-family: "Times New Roman"; mso-ansi-language: #0400; mso-fareast-language: #0400; mso-bidi-language: #0400 ;} "}

    Depending on how many sources are entered labview code through a loop For which in fact a 'smooth box' visible or invisible, on the adjustment of gain control depending on whether the current detector is greater than the seizure of the number by the user.  This loop slows down the program because it works 128 times (max number of detectors) and has 4 structures deal (2 sets of wavelengths, 2 for each breast) with 64 nodes of property each where it is visible property to enabled or disables the box with that covers the detectors.

    I was wondering if there was an easier way to enable or disable controls for unused detectors, not only that slows down the program but to reconfigure the data to use more sources, I stop the program and restart it.

    Any advice on the creation of a dynamic front would be appreciated


  • Another way to achieve this?

    SQL > desc cname
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    IDENTIFICATION NUMBER
    CTYPE VARCHAR2 (10)
    CLIA VARCHAR2 (10)

    SQL > select * from cname;

    CTYPE CLIA ID
    ---------- ---------- ----------
    11 can tst
    12 can tst
    12 ucp nbs
    ASF 12 trp


    SQL > ed
    A written file afiedt.buf

    1 Select a.id, a.ctype, a.clias cname, a, cname and b
    where the 2
    3 a.ctype = b.ctype and
    4 a.clias = b.clias and
    5 * a.rowid! = b.rowid
    SQL > /.

    CTYPE CLIA ID
    ---------- ---------- ----------
    12 can tst
    11 can tst



    SQL >

    Another way to achieve the above output?

    Thank you. :-)

    Maybe

    select id,ctype,clias
      from cname
     where (ctype,clias) in (select ctype,clias
                               from cname
                              group by ctype,clias
                              having count(*) > 1
                            )
    

    Concerning

    Etbin

    NO TESTS because I did not access database on weekends and holidays

  • Figure numbering: is there a more automated way?

    I have an InDesign book composed of 12 chapters indd files. Each chapter has up to 50 digits. These figures are provided with a 9 pt text label adjacent to the image or illustration. No subtitle, just the phrase "Figure 1-2, 1-2, etc.

    The figures are also referenced in the text... "as shown in Figure 1-2".

    So is it possible to link directly, whereas if I change a Figure number in the text, it changes out to Figure? (or vice versa). Or better yet, if I add a Figure number it stunts the change all the way to follow?

    Problem is now I do everything manually, so if a wise guy adds a number at the beginning of a chapter, I need to manually adjust both in the main story and each individual data.

    Maybe a plug-in exists?

    I look forward to suggestions of all workflows. Thank you

    Not automatic (unless you ask someone to write a script that helps out), but with a little work...

    To automatically generate the numbers:

    • Create each chapter as an InDesign Document.
    • Use the Text Variable - chapter number to set the number of chapter for InDesign documents (I guess that the number prefix at the forefront of hyphen to a chapter number)?
    • Define a Paragraph Style with a numbered list of type your Figure of legend, you can define a new list. Set up number using "literal text" followed by Figure number placeholder 'chapter number' a hyphen and number number placeholder current level .
    • Defining an Object Style that has the paragraph Style enabled and apply this style to object to all managers of legend in your document (I hope I got this correct your writing? that legends are in particular unthreaded text frames?)
    • No text will appear in text blocks at this point unfortunately (text appears if the figures were inline text that followed other text).

    The trick is to then insert a character not in frames, as well as the legend of the Figure appears. For example an late Style nested here character. As soon as this character appears, the text of the legend of the Figure should pop up.

    Restart the numbering for each document
    Figure numbering will be continuous through the documents, but that is easily fixed, by setting manually "restart numbering" in the first figure in each chapter.

    You can now use the function references available in CS4 and CS5 to refer to these numbers. If there are other figures inserted, cross-references will display automatically a little yellow WARNING marker, indicating that the text of the referenced paragraph has updated. Select all 'modified' XREF, and you can update all in one shot.

    Hope this helps,

    CARI

    --

    www.carijansen.com

    www.Twitter.com/carijansen

  • More simple way to complete the xml data in a drop-down list

    Hi all

    I have a dept.xml as below.

    <? XML version = "1.0" encoding = "UTF-8"? >
    < departments >
    Department < and > account < / Department >
    < departmentAdmin < / Department >
    Department < and > Security < / Department >
    < / departments >

    Can I know what is the easiest way to fill in the 'account', 'Admin' and 'Security' in a drop down list?  And how?  Can we by befriending pure?  Or has done by the script?

    Thank you all!

    CL

    To embed the XML data in the PDF file, open it in Acrobat and then:

    Forms-> manage form data-> import data.

    And you choose XML file.

    I hope this helps.

    Diego

  • I want to delete one of the tools of my toolbar and the instuctions taking me to 'add ons' is a non-starter, so what's the simple way to do this?

    I fell once trial-error on how easy peasy to do this. All my research I continue to take in complex 'solutions' which are not cut.

    I do not know if you have a right-click of the mouse, but using either make a right or Mac, Ctrl click (on-click) on a toolbar button or the command should give you short a context menu with the option to remove from the toolbar.

    WARNING: Cannot delete the elements incorporated into the address bar without removing the entire address bar.

    If something is wrong:

    • Some add-ons keep forcing their buttons on the bar. Annoying, but I don't know of a way to block to do.

    Success?

  • my screen move? could you please tell me a simple way to solve this problem? __

    Remember - this is a public forum so never publish information such as email or phone numbe

    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    I answered the question of the anotehr with a solution that can help you. Please read my solution here:http://social.answers.microsoft.com/Forums/en-US/vistaperformance/thread/d60243f4-6e14-4bd6-aed4-743b5cb790d2/#a6cdc490-7b78-48a8-961d-73d73ee0c870.

  • I replace a website done previously before Page with a new site that I built in Dreamweaver, but wants to keep the URL address, what is the best way to achieve this?

    I replace a site is at the top with a new website that I'm building in Dreamweaver, but want to keep the same URL which is the best way to go about this?

    If you want to keep the same hosting provider, you have nothing to do. Just delete the old files of the site and download your new.

Maybe you are looking for

  • access to my email after firefox asked me about it may not need help

    Firefox asked me if I wanted to make a link to my email. I said yes, not knowing what this was.now I can't access my emil thrugh 8 windows as before. I can't find any link or tab to this topic on firefox.how to return to what I had before?

  • Satellite L50-B-15F - flashing light in case of suspension

    Hi, I realized there is no light or just another indicator when the laptop is suspended, how can I enable this feature? Thank you

  • Impossible to update my windows xp after factory reset

    Original title: unable to update my windows xp When I visit the Microsoft Windows Update. This will be displayed. The website has encountered a problem and cannot display the page you are trying to view. The options provided below may help you solve

  • Lack of Application Acer

    Hello.I need Application Acer this lack in my Netbook... I have reinstall my Netbook because My Hard Drive was Broken.My father has bought the new Hard Drive with 500 GB... And I need Acer request that come with my Netbook.One, why Acer eRecovery Say

  • Wireless connection to my HP Officejet 6500 709 has

    I have a HP Officejet 6500 709 a.  I want to move it to a location that is not in close proximaty to my modem.  My printer has a wireless radio?  Must be connected directly to the modem?  I have a wireless network in my house, but the only way I can