Having alot of trouble with a query

Hey, I'm having trouble with a query for an assignment. The questions states
Find the name of the highest earning employee in each location, excluding managers, salespeople and the president
The problem I'm having is that my query returns the highest earning employee from each location perfectly, but one of those returned is a salesperson, so the next highest earning person in that location should be returned.
We are also not allowed to create a temporary table
Here's my code so far
select
e.first_name,
e.last_name,
e.salary,
l.regional_group
from employee e
inner join department d
on d.department_id = e.department_id
inner join location l
on l.location_id = d.location_id
where e.salary = (select max(e2.salary) from employee e2
inner join department d2
on d2.department_id = e2.department_id
inner join location l2
on l2.location_id = d2.location_id
where l2.location_id = l.location_id
and e.job_id !=672;
the job_id refers to what job title they have
and here's the schema below
Schema
Any help you could give me on this would be fantastic as I have been pulling my hair out over this for the last day.
Edited by: 837562 on 17-Feb-2011 02:14

Maybe you can try the below:
with job_location as
select 1 location_id, 'loc1' regional_group from dual
union
select 2 location_id, 'loc2' regional_group from dual
department as
select 1 department_id, 'dept1' dept_name, 1 location_id from dual
union
select 2 department_id, 'dept2' dept_name, 2 location_id from dual
job_FUNCTION as
select 1 job_id, 'MANAGER' job_function from dual
UNION
select 2 job_id, 'SALES' job_function from dual
UNION
select 3 job_id, 'PRESIDENT' job_function from dual
UNION
select 4 job_id, 'REST_1' job_function from dual
UNION
select 5 job_id, 'REST_2' job_function from dual
employee as
select 1 employee_id, 'a' last_name, 100 salary, 1 department_id, 4 JOB_ID from dual union
select 2 employee_id, 'b' last_name, 200 salary,1, 5 from dual union
select 3 employee_id, 'c' last_name, 300 salary,1, 2 from dual union
select 4 employee_id, 'd' last_name, 400 salary,1, 2 from dual union
select 5 employee_id, 'e' last_name, 500 salary,2, 3 from dual union
select 6 employee_id, 'f' last_name, 600 salary,2, 3 from dual union
select 7 employee_id, 'g' last_name, 700 salary,2, 4 from dual union
select 8 employee_id, 'h' last_name, 800 salary,2, 4 from dual
select
regional_group, employee_id, max_salary
from
select e.regional_group, b.department_id, employee_id, salary, max(b.salary) over (partition by b.department_id order by b.department_id) max_salary
from
employee b,
job_function c,
department d,
job_location e
where
b.job_id = c.job_id and
b.department_id = d.department_id and
e.location_id = d.location_id and
c.job_id not in (1,2,3) 
) where salary = max_salary;
"REGIONAL_GROUP"     "EMPLOYEE_ID"     "MAX_SALARY"
"loc1"     "2"     "200"
"loc2"     "8"     "800"

Similar Messages

  • I am having alot of trouble with svg files is there some one well versed with adobe svg file

    I am having alot of trouble with svg files is there some one well versed with adobe svg file

    Clearing out cookies while in gmail helped me to get all functionality back. One of those sites must have messed with gmail. Thanks so much for the help.

  • I am having alot of trouble i want to use imessage but everytime i turn it on it turns on but doesnt work and it says verifying but its verifying my old number and i need it to verify my new number but it wont let me

    i am having alot of trouble i want to use imessage but everytime i turn it on it turns on but doesnt work and it says verifying but its verifying my old number and i need it to verify my new number but it wont let me

    You can likely download the last compatible version by:
    Starting when iOS 7 was released, Apple now allows downloading the last compatible version of some apps (iOS 4.2.1 and later only)
    App Store: Downloading Older Versions of Apps on iOS - Apple Club
    App Store: Install the latest compatible version of an app
    You first have to download the non-compatible version on your computer. Then when you try to purchase the version on your iPod you will be offered a compatible version if one exists.

  • I just uploaded the latest IPad software to my IPad and am now having loads of trouble with the device recognizing "online buttons", that is, links, etc.

    I just uploaded the latest IPad software to my IPad and am now having loads of trouble with the device recognizing "online buttons", that is, links, etc.  what can I do?

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    -  Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • Why am I having so much trouble with my iPad air 2 reading and remembering my fingerprints?

    Why am I having so much trouble with my iPad air 2 reading and remembering my fingerprints? Even if I enter the same finger 5 times, it only works once or twice.

    Try this -> http://m.facebook.com
    which is the mobile optimized page of FaceBook.

  • I  have been having nothing but trouble with OS 10.6.8.  Many of my appliatins will not work..  HOw can I revert back to a previous version of OS x?

    I  have been having nothing but trouble with OS 10.6.8.  Many of my applications will not work..  HOw can I revert back to a previous version of OS x?

    Before you revert anything try this:
    Reinstall OS X without erasing the drive
    1. Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Reinstall Snow Leopard
    If the drive is OK then quit DU and return to the installer.  Proceed with reinstalling OS X.  Note that the Snow Leopard installer will not erase your drive or disturb your files.  After installing a fresh copy of OS X the installer will move your Home folder, third-party applications, support items, and network preferences into the newly installed system.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.
    Next time don't post something like "nothing but trouble." Tell us exactly what the trouble is and provide any additional information such as error messages.

  • Ever since I update my iPhone to ios 7 I been having so much trouble with it. I lost my contacts, my notes, I set a ringtone and it change it... What should I do?. I love iPhone but this is making me angry.

    Ever since I update my iPhone to ios 7 I been having so much trouble with it. I lost all my contacts all the time, my notes, I set a ringtone and it change it... What should I do?. I love iPhone but this is making me angry. :(

    Basic troubelshooting steps have not changed in iOS 7.  Restart, reset, restore from backup, restore as new.

  • CanI downgrade back to the previous, non4.0 version? I am having too much trouble with 4.0

    How can I downgrade back to the previous, non4.0 version? I am having too much trouble with 4.0, such as:
    1) cannot save multible tabs in bookmarks
    2) 4.0 is not faster, perhaps even slower
    3) crashes often, especially when I scroll through my emails in Yahoo email.
    4) Moved the "stop loading" and "refresh" buttons to the right, ala MS Internet Explorer. I liked your old location better.
    Thank you,
    Gary Bright

    try this link http://www.mozilla.com/en-US/firefox/all-older.html
    Uninstall 4.0. DO NOT CHECK "Remove my Firefox personal data"

  • Having a little trouble with the "export" dialog box

    Hi all,
    When I get to the export dialog box, I'm not able to type directly in the "Custom Name" space.  I have to click around and fiddle with some of the drop-down menus (and then get back to the "name format" that I like) and only then can I triple-click or backspace on the former name and input a new name in the "Custom Name" blank.
    Also, the "Export Versions" tab is highlighted, but hitting the "return" key doesn't make the export happen.  I have to mouse up to that button and click it that way.
    Is anyone else having any trouble with inputting information on the export page?  And ideas?
    Thanks as always.

    Yes, the name format is Custom Name with Index.  But when I click in the field, I can't edit it.
    Mark,
    For me, this preset is working well. Have you checked, if the preset for  "Custom Name with Index" correct?  You can verify it, by setting the "File Naming" format to "Edit". The preset should look like this:
    I'd try to edit the preset, save it, and edit it back, to create a new preset file.
    If that does not help, remove the user Aperture User Preferences, as described in this document:  Aperture 3: Troubleshooting Basics
    And as I said, hitting "return" doesn't start the export.
    That also your "Export" button is not responding to return, even if it is highlighted in blue, is a sign, that your preferences file might have a problem.
    Regards
    Léonie

  • I'm having so much trouble with my I.D account

    I'm having sume trouble with my account I.D plz help.

    If you say what the problems are then somebody on these forums might be able to help.

  • Having trouble with join query

    Hi,
    I have two tables in my database, class and document. They look like this:
    Class
    Class
    classdescription
    Document
    documentid
    class
    document.class is a foreign key pointing to class.class. I want to find out how many document there are for each class, so I have the SQL statement:
    SELECT class.class, count(class.class) as numDocs, classDescription from class, document where class.class = document.class group by class.class, classDescription order by numDocs DESC
    However, if there is a class with no document, I also want it listed with the value 0 for numdocs, however this query doesnt seem to return class which have no documents.
    Can anyone provide me with help for this?
    Thanks!

    Could this be what you wanted?
    SELECT   CLASS.CLASS, COUNT (document.documentid) AS numdocs, CLASS.classdescription
        FROM CLASS, document
       WHERE CLASS.CLASS = document.CLASS(+)
    GROUP BY CLASS.CLASS, CLASS.classdescription
    ORDER BY numdocs DESC;C.

  • Trouble with power query as import facebook

    Hi I am using Windows 7 64 bit with Office 2013 Pro 64 bit. I am using the Microsoft power query add
    in  64 bit . 
    View comment of feed error follow:
    DataSource.Error: An unknown error occurred
    Details:
        https://graph.facebook.com/136807033073095/feed?limit=1000&until...
    Please help!

    Sorry it took so long for you to get any reply! Are you still having this issue? Could you please provide some more information about the steps you took to get the error?

  • Still having a little trouble with template

    Hi,
    Can anyone please take a look at the following page and tell
    me what's going on with my faux columns?
    BPI
    Test Site - Activities Page. Since my pages are varying heights
    I eliminated the "page height" command for my center content div,
    using the "clearer" convention in my style sheet. Seems to work
    great in IE but I'm having a problem with FF and Netscape. I'm
    thinking that the Code isn't quite right somewhere in my template
    page (pasted below) but I'm not sure. Any help appreciated. Thanks

    It works to clear the floats BEFORE the containing div is
    closed - that's
    what forces the container to re-contain all of the stuff
    that's floated.
    Your code was clearing the float AFTER closing the container,
    and that
    doesn't do the job.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "webmom24" <[email protected]> wrote in
    message
    news:e86m4j$es$[email protected]..
    > Thanks Gary. That worked. Of course, I'm curious now why
    the code works
    > fine as
    > is on the home page (with it in the other position). Can
    you tell me what
    > this
    > little bit of code does? I'd like to try and understand
    it... right now
    > it's a
    > mystery to me why it works LOL. Thanks again.
    >
    > Maureen
    >

  • Trouble with simple Query by Example

    Hey all, I am well aware that similar topics are all over the forums. I've exhausted myself fishing around for just the right thread.
    I am new to APEX. I have this book "Easy Oracle HTML-DB". It is somewhat helpful, but its examples are hard to follow - possibly because the product keeps moving along.
    I have a simple single table listing report. I wanted to add some selection criteria and was attempting to do so in a new region on the same page as outlined in this book. I added a few text fields and tied them into the query without issue. To submit the criteria, I added a "Go" button (just like the book says) and tied a "Reset Pagination" process to it.
    The book example doesn't specify button branching conditions. Without any though, clicking "Go" causes an error: "ERR-1777: Page XX provided no page to branch to." . So I added a branch back to the same page. Now it appears to be working, but it resets all my selection field values and runs the same report over again.
    I think a workaround is simply to put the criteria in a separate page altogether. I'm just about resigned to taking this approach. It sure looks like people do this all the time though. What did I miss ?
    Thanks in advance,
    Snake

    Rene said: "It's also nice to add : onKeyPress="checkEnter(event)"
    to the HTML Form Element Attributes of the items in the search region. This way you can also start the search by pressing Enter in the item."
    Hi Rene,
    I'd like to include the feature, but the action is no different with or without this attribute. When you press enter, it just stays there in the field.
    Nice to note though that most every behavior I've checked is the same whether using Firefox or IE. I like browser independence.
    Snake

  • Having to much trouble with arch. What other distros do you recomend?

    I've been trying to geet arch running flawlessly on my thinkpad x61 for the last month.
    But I've run in to some problems that I can't solve.
    The iwlwifi-4965-ucode drivers unstable and gives me kernelpanics. Tried to roll them back but nothing happend.
    I'm having problems with my xorg. It worked flawlessly under kubuntu but in arch I get some strange lines when things moving horizontaly on my screen. Like the image is splitting into 2 pieces instead of one. Have been configuring my xorg for weeks without any result.
    Feels like I need some other distro.
    I like the whole from scratch idea.

    timetrap wrote:
    I think you misunderstand what a linux distro is. There is no secret sauce that makes one distro better than the other. They all have the same ingredients. What make distros different is how they put the same ingredients together.
    I am assuming you went here http://www.linux-on-laptops.com/lenovo.html and looked at this http://pi-ist-genau-3.de/?page_id=344
    And I am assuming you looked at this too (regarding your wireless) http://bugs.archlinux.org/task/10984
    tried the xorg.conf from "debian on lenovo x61" and its a dualscreen configuration. And I actually had a 1680x1050 samsung syncmaster standing in a closet so I plugged it in and tried to play movies @ both screens and I get the same result on both screens no matter what mediaplayer I run. So something must be wrong with my intel driver?
    My xorg.conf before I tested the dualscreen xorg, witch gives me the same problem.
    Using xf86-video-intel driver.
    And about the wifidrivers. A bug is allways a bug no matter if it's known or not. Still a problem.
    Last edited by bredin (2008-08-18 20:14:30)

Maybe you are looking for

  • Running Out of Space... Help!

    The hard drive on my 250 GB Macbook is almost full (I have 1 GB left).  My 500 GB external hard drive is almost full (I have 23 GB left and it requires 27 GB to do the daily back-up).  Without buying a new laptop with a bigger hard drive and without

  • I can't install a update softwares on os x Mountain Lion

    Hello After installing an SSD in a MacBook Pro (replacing the internal hard disk of origin), I tried an installation of OS 10.8 (Lion Mountain) from an USB key created with DiskMaker X application. Then, I moved iLife'11 from an official installation

  • Sale tax related

    Hi Experts, While releasing billing doc (VF02-Invoice no is 13099358) I am facing following error. Could you please help me on this? Because of this am not able to see accounting document. Diagnosis: No tax items exists for tax code V0 in  a GL accou

  • Oracle.DataAccess.Client.OracleConnection vs. System...

    I am wondering why this code: Dim builder As New Oracle.DataAccess.Client.OracleConnectionStringBuilder builder.DataSource = "datasourcename" builder.UserID = "user" builder.Password = "pass" Dim oraConn As Oracle.DataAccess.Client.OracleConnection =

  • Which application is making "DriverManager.getConnection(URL,p)" call?

    Hi All, I have 15 domains each having 100 or more applications[.ear,.jar,.war] on a single Solaris box[Dev Env]. One of these applications[out of 100*15] of one domain[out 15] is making direct JDBC connection.[DriverManager.getConnection(URL,p)]. Now