How to choose the Department with employees in the same line?

Hello world

I need to make this request,

Suppose we have 2 departments with n used on each Department

I need to select the departments with only 2 employees in the same line, example here

Department Name of Department Employee1 Employee2
10HUMAN RESOURCESMarcSteve
20HEPaul
30New Department
40FinanceJeanMichael

This query below did not work because it only displays the first employee, but I need to display 2 employees (same as the above table)

select
deptno,
(select ename from emp, dept where rownum =1 and emp.deptno = dept.deptno) employee1,
(select ename from emp, dept where rownum = 2 and emp.deptno = dept.deptno) employee2

from dept;

...

I did this, but with the function returning the Emp2Dep1 Emp1Dep1

function get_ename(p_dept number,p_col number)
return varchar2
is
    v_ename varchar2(4000);
    v_first boolean := true;
BEGIN
        select ename
              into v_ename
              from
                  (
                  select ename, rownum as rn
                  from (
                        select ename
                        from emp ,dept
                        where    emp.deptno        = p_dept
                        order by 1 asc
                        )
           
                  )
              where rn = p_col;       
          

     return v_ename;
END;

and simply put

select
get_ename(deptno ,1 ) employee1,
get_ename(deptno ,2 ) employee2
from dept;

Is there a better way to do it?

NB: database 11g

Thank you

Select the Department, employee1, employee2

(select Department, name, cnt

(name, department, row_number (select) at the NTC (partition by order of the Department by null)

employees

)

where NTC<=>

)

Pivot (max (name) of the cnt (1 as employee1, 2 as employee2))

order by Department

DEPARTMENT EMPLOYEE1 EMPLOYEE2
10 Marc Steve
20 Paul -
30 - -
40 Jean Michael
50 Alpha Beta

Concerning

Etbin

Tags: Database

Similar Questions

  • How to repeat the same line more than once in the report 10g

    How to repeat the same line more than once in the report 10g

    If I print the barcode more than once
    in the report;

    Published by: user11106555 on May 9, 2009 05:50

    OK, thought it was just a recording, then try:

    SELECT COL
      FROM TABLE,
           (SELECT 1
              FROM DUAL
             CONNECT BY ROWNUM
    
  • How to choose the same color in the text and objects?

    Hello

    I have a document with about 30000 objects include text, small filled circles and paths between the circles (see small screenshot attached).

    Capture.PNG

    I need to separate into groups based on color in order to later completely redraw. I would like to be able to select all elements with the same color but the problem being that the railways have only line-color, the only circles fill color and text only-color of the text. I can't seem to find the correct command in "identical". Any ideas of how I could do?

    Thank you very much!

    PER DAY

    more precisely what you're asking is done in the following way:
    Since you have only 3 types of select:
    First set up your magic wand by double-clicking on it in the tools Panel and configure it to contours and funds, also you can bump the tolerance up to about 75. now select your text object , and then use select even--> fill color, this should get your filled objects also, then with the magic wand tool, shift click the same traits in the selection of color and you should have all 3.  Now put it in the layer that you want, save the selection, there are other more obscure options.

    However if you just divide it into groups... try this:

    go to your layers panel and make a layer for each color

    use the same for each type.  for example, select same line color for all similar objects outline color, and then drag the color "block" in the layers panel to the appropriate layer.  Repeat for every thing.

    Finally, if you just want to change the colors on the fly, for something so huge, try edit--> edit color--> work Recolor

    Just play with it, you will see only a few colors, double click on the box, the arrow worms with color in it and (with illustrations to redefine colors in the verified corner) you will see change as you select the new color., in

    I am interested in the most direct way, if anyone knows, something which would, in one stroke, select objects containing color wherever it is.

  • How to choose a print with black ink only on the Office Jet Pro 8600?

    How to choose a print with black ink only on the Office Jet Pro 8600?

    Please read this post then provide some details.   What operating system? For Windows 7, the setting must be in the Advanced tab as shown below.  Note that color ink may still be necessary to avoid that the print head clogged, see here for more information.

  • How to choose the slot one of the two bunk?

    How to choose the slot one of the two bunk?

    Select the two points to cross the selection with the open selection tool, and then clear the high point on the page by holding shift and clicking on it.

    or vice versa. Select the high point of the page first and then select now shift. the high point of the page désélectionnera.

  • How to choose the scheme of work of a different database instead of the database target

    Hi everyone, can you please answer to my problem.

    Q1.is it is mandatory that the two target schema schema and work must present in a database.if not then How to choose the scheme of work of another data base instead of target database schema. Please suggest.

    __Description__

    My work, my work patterns in odi's in a database schema and target in a different database,
    Now I'm dataserver with identification of the target or credentials of scheme work information.
    Here's the problem.

    I can't see scheme of work in the drop-down list when you create the physical schema with data server with the credentials of the target.

    It's obvious that he cannot show the workschema which presents in an another database.because - database server has the schema of the target database credentials.

    Vice versa

    Please suggest

    Concerning
    Chantal

    Hello

    Your KM will create the tables for working in the schema, you write to and that's why you have the problem:

    create table< %="odiRef.getTable" ("l",="" "int_name",="" "w")="" %="">

    I don't know of an option to replace this 'W' that will say 'go and get work in the staging area, I've specified.

    I guess that you can customize the KM and pass all the commands to Execute on the Source tab, or I guess you could specify the schema for each of the steps to be the logic diagram of the various staging areas.

    BUT I don't know if it would work throughout and I think it will create a massive Mount of work unnecessarily.

    Is there a decent reason why you can not have the staging area on the target?

  • How to better master with this model s/n, sides IN and OUT in the same line.

    Hi all!
    I'm just facing some old historical table where, to the transaction recorded in the same line, something like:

    column name
    ==============
    ref_no,
    x_id,
    product_id,
    product_amt,
    -* IN part
    in_flag-(IN)
    in_customer,
    in_address,
    -* PORTION
    out_flag-(OUT)
    out_customer,
    out_address

    Nice shipping biz where we can have the two sides met in the same line, they have same value for IN and OUT_flag = actual values 'IN' and 'OUT', woou!
    I really expect to have this table in different model where a line is an entry, probably with PK = ref_no + in_out_flag.
    But it looks like I can do anything on this design, and now I choose upong xactions request entry and EXIT, IN/OUT fixing portions on a common part with the UNION. This, the only way I can see how to solve this problem, or I'm not right? And I need to pack all in the stored procedure.

    Appreciate your comments how to do this, I'm really new to Oracle, however have some exp.
    And comments about these models db as well! -).


    Best
    TR

    I don't understand what problem needs to be solved.

    What criteria an independent observer would conclude that a correct solution has been posted.

    Published by: sb92075 on September 11, 2010 17:19

  • How to choose the display by default when you use two screens on my Mac Pro?

    How to choose the display by default when you use two screens on my Mac Pro?

    The default view when you have several is made that you drag the little icon in the menu bar in this pane:

    .

  • When you export (share) a project, how to choose the thumbnail of the freeze frame which restores the clip?

    I just shared (exported) a project that is a simple take a clip for a friend who has downloaded on its website. The problem is that, when the video ends by playing on his site, he returned to a freeze frame that seems completely random and is not the image I want. How to choose the exact image that the video will return as "thumbnail by default?"

    Thank you

    Kevin

    Cannot set lla at the FCC. Many layout site Web apps will allow you to set the poster frame for the video files.

  • How to choose the download location? download automatically to the users in c drive folder. I want to change it... Please help me...

    How to choose the download location? download automatically to the users in c drive folder... I want to change my office... Please help me out...

    Tools-> Options-> save-> click on the Browse button and find the folder where you want to save the files.

  • HP pavilion 15-e034tx: how to choose the right RAM for laptop

    How to choose the right RAM for my laptop (Pavilion 15-e034tx). I know I should buy DDR3 ram.

    Are there other factors should I consider when buying one? I got 2 slots for ram, which od these combos are possible?

    1-4 + 4 GB
    2-4 GB + 8 GB
    3-8 GB + 8 GB

    Thank you

    From the Manual:

    Two customer accessible/upgradable memory module slots

    Support for dual channel DDR3L (1600 MHz)

    Support 8192 MB RAM system in the following configurations:

    8192 MB (8192 MB × 1, × 4096 MB 2)

    Manual download link

    See page 53 for instructions. Memory access is easy via the service Panel. This is the part number for the approved 4 HP concert module:

    4 GB (PC3L, 12800, 1600 MHz) 691740-001

    http://www.Amazon.com/HP-691740-001-4GB-1600MHz-PC3L-12800/DP/B00CI08FX4/ref=sr_1_2?ie=UTF8 & qid = 1451655870 & SR = 8-2 & Keywords = 691740-001

    A 8 GB module is listed in the manual, and it's a 3rd generation of processor i5 I suspect 2 x 8 = 16 concerts would work, but strictly following the manual your only option is to add a 4 GB for a total of 8. Most users really not more 8 GB and adding a second identical module will allow two-channel operation, so you should see a noticeable jump in the overall performance.

    If it's 'the Answer' please click on 'Accept as Solution' to help others find it.

  • 4540 proBook s: how to choose the right network driver

    Hello guys. I clean installed Windows 7 Professional. Now, I see that I can not connect my computer to the internet, so I need to install the network drivers. I wen to the HP website and saw that there are 19 different network for my laptop drivers.
    How to choose the right method?

    Hello:

    Below are the links to the ethernet and wireless drivers you need...

    Wireless:

    This package contains the installation package driver for Ralink wireless LAN controllers in the laptop models running a supported operating system.

    File name: sp66089.exe

    This card also needs a bluetooth driver...

    This package contains the OS driver installation package for the Ralink Bluetooth in laptop computers running taken in charge.

    File name: sp59632.exe

    Ethernet:

    This package provides the driver for the Ethernet Realtek controller in the laptop models running a supported operating system.

    File name: sp63213.exe

  • How to map the same tag of the element with a different value in BI Publisher rtf model.

    Hello

    I have an xml file with the same name in the < tag > element and I do not know how to associate the same < tag > element to different string in the document rtf template attribute.

    For example: "' Eswitch <number > is repeated in this xml file, when I am mapping this element to the document rtf with a different string, I have same value 'D00002 ' . I should get values D00002 and DMR00002.

    < document >

    < TitleBlock >

    < number > D00002 < / number >

    < itemType > Document < / itemType >

    < lifecyclePhase > preliminary < / lifecyclePhase >

    < description > gtedgg < / description >

    < shippableItem > n < / shippableItem > < / cartridge > < / Document >

    < DMR >

    < TitleBlock >

    < number > DMR00002 < / number >

    < itemType > DMR < / itemType >

    < lifecyclePhase > preliminary < / lifecyclePhase >

    test nomenclature model bom1 < description > < / description >

    < POS > < value > Test < / value > < / POS >

    < shippableItem > n < / shippableItem > < / cartridge > < / DMR >

    < / AgileData >

    I followed steps below for map document model rtf with the same tag xml with a different value.

    1. install Office word 2013.

    2 BI Publisher for desktop software installed. It will add a BI Publisher plugin to the word document.

    3. with the help of desktop publisher BI, created a model of document rtf file.

    4 imported the document rtf template example xml file.

    The data is loaded successfully.

    5 tires model rtf field symbol to map the tags to xml to rtf document attributes element.

    7 saved the document in PDF format.


    Thank you

    Please mark it correct so that it is useful for others to find the solution to a similar request.

  • How to choose the value of a string are numeric together and words of letters (for example, TEST)

    Hi all

    How to choose the value of a string are letters (for example, TEST) and all numeric...

    for example
    TEST 123456
    TEST 34567
    123456 ABCD
    1234 TEST
    TESTING 12345
    TEST 1@234$
    YOUR T 123456

    I want the results of the query as below.
    TEST 123456
    TEST 34567

    And I tried to use regexp_like in this case but without success. See the code below.
    SELECT * FROM TABLE WHERE regexp_like (Description, ' [TEST] % & [[: digit:]] + $');

    How can I do this, please answer.

    Thank you

    WF

    If you want to return only the rows that contain the string 'TEST', followed by zero or more space characters, followed by one or more digits?

    How about this:

    SELECT *.

    FROM my_table

    WHERE REGEXP_LIKE(description,'^TEST\s*\d+$')

  • How to make the same effect of scrolling like Tumblr (beginning Web page) with Adobe Muse?

    How to make the same effect of scrolling like Tumblr (beginning Web page) with Adobe Muse?

    I used Adobe Muse since the day it first came out, I played with the timings and effects of scrolling a lot. Tumblr landing page scrolling is very nice, I can see why you want a similar effect. Something similar could be created using the scrolling in AdobeMuse effects, especially if you familiarize yourself with the scrolling of the transparency. Start with a color block simple try it scroll up to double speed, then add items to the next page with the scrolling transparencies. Best practical work, use layers to do this, it makes things so much easier when you need to edit the page.

    Once you have played with the effects of scroll, you will begin to note how the elements of the Tumblr page can be re-created. This will be a sharp learning curve, but very doable in Muse for a similar effect. You will have a number of layers with page elements and new blocks of color on each layer when your done, fine tweaking the movement of scrolling and timings will make perfect. Good luck.

    If not, try adding an animation on board, you can create a Web page in Adobe Edge, but again... probably much more involved learning with this option.

Maybe you are looking for