How to get difference the min of two columns having different conditions ?

Hello,
I am trying to write a query which staisfies the following condittion. I have a table emp which has the following colums empno,ename,deptcode,empstat_code,salary.
The salary of employees depends on the empstat_code.
For a given deptcode, I have to compare the mimimum of salaries for empstat_code 'A' with the minimum of salaries for empstat_code 'B' and then a get a difference between the two.
How can I do this, please advise.
Thanks
fm

Something like this perhaps.
create table my_emp as
select
from scott.emp
alter table my_emp add emp_stat varchar2(1);
update my_emp set emp_stat= case when mod(rownum, 2) = 0 then 'A' else 'B' end;
select * from my_emp;
TUBBY_TUBBZ?select
  2        min(decode(emp_stat, 'A', sal)) as min_A_sal
  3     ,  min(decode(emp_stat, 'B', sal)) as min_B_sal
  4     ,  deptno
  5  from
  6     my_emp
  7  group by
  8     deptno;
         MIN_A_SAL          MIN_B_SAL             DEPTNO
               950               1250                 30
              2975                800                 20
              1300               2450                 10
3 rows selected.
Elapsed: 00:00:00.71Keeping in mind that MIN will return NULL if there are no values for a given emp_stat and deptno combination. So you would have to account for that however your business rules tell you to account for it (likely using NVL to 0)

Similar Messages

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to get all the values in one column of a JTable

    How to get all the values in one column of a JTable as a Collection of String.
    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column.

    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column. You could always write a custom TableModel that stores the data in the format you want it. It would probably be about 50 lines of code. Or you could write a loop in 3 lines of code. I'll let you decide which approach you want to take.

  • How can I setup an .indd with two columns with different threads so that I can export to epub?

    Hi all. Sorry, english is not my native language. I´ve made an .indd: each page has two columns with different threads (is a bilingual text). When I export this .indd to .epub only appears one column from a thread following the next thread. What can i do to fix this? My indesign is CS6
    Thank you

    There are fixed format EPUB files as can be used for children's books, etc. where there are a lot of illustrations. However, those are very work-intensive to produce. I've never worked on one.
    Anne-Marie Concepcion did a Lynda.com video on producing one.
    Rorohiko produces a product called ePubCrawler which can help in produced fixed format EPUB files:
    Fixed Layout EPUB Assistant In InDesign: ePubCrawler | Rorohiko ...

  • How can I get extract the data between two cursors on an XY graph

    How can I get extract the data between two cursors on an XY graph

    Well, you say xy graph, so this might be a more complicated problem.
    For a waveform graph it's trivial. Simply get the two cursor indices (property: cursor index) and apply them to array subset of the data. Is that all you need?
    Here's how the above code would look like. using cursor.index instead of cursor.x elimnates the need to include scaling information.
    For an xy graph, there could be multiple segments (e.g. imagine a spiral that passes the desired x range multiple times from both sides). This would neeed significantly more code for a general solution.
    Message Edited by altenbach on 11-24-2009 07:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    cursorsubset.png ‏17 KB

  • How do you get the sum of two columns multipied together?

    I can't seem to figure out how to get the sum of two columns multiplied together without having to manually type out each location (example: A1*B1+A2*B2+A3*B3, etc..).  Though the idea seems to be rather simple, everything I have tried has only given me an error.  I know there must be an easier way of doing this, but I get lost in the explanations given in 'help' area of numbers, can someone help me?

    C3=SUMPRODUCT(A3:A18, B3:B18)
    the function SUMPRODUCT() takes ranges and multiplies corresponding cells in the ranges, then adds them together.
    I the case I show SUMPRODUCT() performs:
    A3*B3 + A4*B4 + A5*B5 + A6*B6 + ... +  A18*B18
    If you want to perform the same operation on the whole column (s) you could modify the formula:
    C3=SUMPRODUCT(A, B)

  • How can get difference between 2 dates in the form of days

    how can get difference between 2 dates in the form of days

    Hi,
    Check the following program:
    REPORT ZDATEDIFF.
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Regards,
    Bhaskar

  • How to get all the values from the dropdown menu

    How to get all the values from the dropdown menu
    I need to be able to extract all values from the dropdown menu; I know how to get all those values as a string, but I need to be able to access each item; (the value in a dropdown menu will change dynamically)
    How do I get number of item is selection dropdown?
    How do I extract a ?name? for each value, one by one?
    How do I change a selection by referring to particular index of the item in a dropdown menu?
    Here is the Path to dropdown menu that I'm trying to access (form contains number of similar dropdowns)
    RSWApp.om.GetElementByPath "window(index=0).form(id=""aspnetForm"" | action=""advancedsearch.aspx"" | index=0).formelement[SELECT](name=""ctl00$MainContent$hardwareBrand"" | id=""ctl00_MainContent_hardwareBrand"" | index=16)", element
    Message was edited by: testtest

    The findElement method allows various attributes to be used to search. Take the following two examples for the element below:
    <Select Name=ProdType ID=testProd>
    </Select>
    I can find the element based on its name or any other attribute, I just need to specify what I am looking for. To find it by name I would do the following:
    Set x = RSWApp.om.FindElement("ProdType","SELECT","Name")
    If I want to search by id I could do the following:
    Set x = RSWApp.om.FindElement("testProd","SELECT","ID")
    Usually you will use whatever is available. Since the select element has no name or ID on the Empirix home page, I used the onChange attribute. You can use any attribute as long as you specify which one you are using (last argument in these examples)
    You can use the FindElement to grab links, text boxes, etc.
    The next example grabs from a link on a page
    Home
    Set x = RSWApp.om.FindElement("Home","A","innerText")
    I hope this helps clear it up.

  • HT201269 How do I keep the contacts in two iPhones separate?

    How do I keep the contacts on two iPhones separate? At present, when I add a contact to my iPhone 4, it appears on hubbies iPhone 4s, If I delete it from his phone, it also deletes from mine. Help please!!

    It sounds as if you are both using the same iCloud account and are syncing via iCloud. You need to have separate iCloud accounts.

  • How to get to the fan of Compaq Presario CQ62?

    I believe there is an issue with the fan of my laptop, and I opened up the back of it in hopes that I could get to the fan and take a peek to see if it was merely a cleaning issue.  I failed to find a way to actually get to the fan.  I removed all visible screws and still couldn't manage to figure out how to get to the fan.  Can anyone offer assistance or point me in the right direction of how to figure this out?  Thanks.

    You unscrew all the screws including the one under the battery.  Make sure you remove all RAM and Hard Drives.  Carefully pry up the key board (if you did miss some screws underneath the keyboard will not come up), DO NOT pry from the bottem or else you can break some of the keyboard wires.  There is one screw under the keyboard, take it out.  There are some wires under the keyboard that you can see pluged into the main circut board remove them all carefully ( the ribbions will come out by lifting the top where the ribbon is connected, and do not forget the one on the top left hand side (careful not to break the wires).   Now from unerneath remove all the doors and unplug the wireless card,  its about 1 1/2 by 1 inches.  Now carfully pry the shell aprt while its right side up ( the mother board is screwed into the bottem half of the shell).  The mother board has two screws holding it down take them out and unplug the wires on the right side and one on the bottem. Now lift the mother board on the right side and carfully slide it out, it may be slightly binded aroung the fan.  The fan is on the bottem of the mother board.  If you want to remove the fan you have to remove the heat sink so you need extra heat sink.
    I hear HP laptops have a lot of fan issues,  I had a HP pavillion 6000 that had fan problems, and now this one.  I sent it off to get the CPU fixed and came back like this.  I do not trust HP to fix my computers any more and do all maintanance my self. 

  • HT4241 How do I use the mini deplayport to hdmi

    How do I use the mini displayport to hdmi on my tv?

    You use something like this:
    http://www.amazon.com/Mini-DisplayPort-HDMI-Adapter-Cable/dp/B003OC6LWM/ref=sr_1 _1?ie=UTF8&qid=1365115124&sr=8-1&keywords=minidisplay+port+hdmi
    Ciao.

  • How to get all the values from a HashMap? thanks

    hi
    can anyone tell me how to get all the keys and their values contained in a HashMap? thanks

    thanks to u all for ur response, i gues if i need to get both keys and values, i need to use keySet() to get a set of keys first and then using each key to get value. is there any other faster way to get both of them (key and value)? thanks again

  • How to get all the values of a variable with F4 with checkboxes to select

    Dear Experts,
    After Executing a query by giving let 3 values(Out of 10 Values) to a variable.
    To give 2 more input values to the same variable(i.e.,total I wanted to give 5 inputs this time ),after refreshing the query,for that variable if I click F4, I am seeing the historical values(i.e.,3) and remaining 7 values also But with out any Check Boxes besides them to select the 2 inputs.
    In the same F4 Screen, If I click all values(an Icon at The bottom),then also Im seeing but no check Box.
    I hve tried by deleting the Delete Personalization also,but no use.
    Please tell me How to get all the values with F4 with check boxes to select ,whatever I want??
    Thanks in advance

    Take a look at the InfoObject and go to the Business Explorer tab. If the 'Query Def. Filter Value Selection' is set to 'Only Values in InfoProvider', you're only going to get the values in F4 that exist in the InfoProvider, not everything in the Master Data. This would need to be changed to the value of 'Values in Master Data Table' if you want it to show everything possible when F4 is chosen.
    Likewise, you're going to need to look at the query and go to the Advanced tab for the InfoObject. Make sure that the radio button for 'Values in Master Data Table' is selected. If not, then you should change that selection.

  • Alter a BAPI Result Table, how to get into the display "loop" ?

    Hello all,
    i have a problem regarding the result rows of a RFC/BAPI Call.
    There are three views, let's say 1,2,3. In View 1, i call a BAPI, and display the results in a table in View 2. I added a button in each row, which calls View 3 and displays some details concerning the selected row.
    I now want to store a flag for each row, that has been displayed in this way.
    In View 3 i store the key value of the displayed row in an own value node in the context.
    When i go back from View 3 to View 2, i want to see that flag (in an extra column) in every row, that has been selected in this session.
    So i do not know, how to alter a single row in the BAPI result table, how to get into the "loop" that is used by WD to display the table.
    already tried a supply function, but i was not able to alter single rows.
    Any suggestions/tips or perhaps code fragments of working supply functions ?
    Thank you !

    Hello,
    I'm not sure whether I understood your problem correctly, but I will try to give an answer.
    The easiest way I see is to copy the RFC Results to a Component Controller Context structure with an additional Flag field. You can use WDCopyService for copying.
    Then on the event of selecting you set your flag as appropriate for you (e.g. if you want to use an image as flag you set the Image path) on the current element of your table. Then display View 3.
    On going back View 2 should show now the new flag values...
    The trick is to copy the values (as at Time structures can not be expandend with new fields) and set the Flag on the onSelect event.
    Hope this helps,
    Frank

  • My mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    my mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    It sounds like you destroyed your boot partition and the recovery partition.  Depending on it's age, your MacBook Air might be able to do a net boot.  Plug and ethernet connection into it and attempt to boot.  If it has the right firmware, it will find a net boot configuration on the net and boot that.  Then it will give you a Recovery Partition like display and allow you to reinstall the OS X version that came with it.... assuming that it was Lion or ML.  If your computer came with Snow Leopard, then even the net boot won't work. 
    At that point you need a bootable USB Key, or an external DVD drive AND a Snow Leopard installation DVD. 
    An Apple Store, if there is one nearby, MAY be able to get you going again.  However, whatever is on the SSD now will be toast too.

Maybe you are looking for

  • WBS element is not getting populated in Excise entry in Project billing

    Hi SAP Guru's We have the case where we are doing the billing from manufacturing plant against Project. While billing WBS element is appearing in the invoice but in excise invoice entry same is not getting populated. This is affecting RR and P&L. Can

  • Question about restoring a backup.

    Question about restoring a backup. I want to restore an old back up to recover messages and photos. If I restore my iPhone with this old backup, will it delete any CURRENT text messages that I currently have on my phone? Same concern current photos o

  • ITunes U doesn't list the videos on Subscribe

    When I view a course listing in the iTunes U section of the iTunes store I see a list with both the video lectures and the supplemental documents like homework assignments and answer keys. When I subscribe to that course, only the documents show up i

  • ALL CS6 Apps Freeze When SAVING file to External HD

    Ok Adobe, help me out here before I reconsider my longstanding glee with Master Suite CS4. I recently subscribed to the Creative Cloud, downloaded, installed and activated ALL applications. All applications have since been updated via the Adobe updat

  • Automating Object Properties

    Hello, I find most of the objects I Build In are a 0.3 sec Dissolve. Is there a way to configure keynote w/ a single control or kestroke so that the selected object is endowed w/ a specific set of properties (e.g, a 0.3-sec Dissolve Build In)?