MIN by CASE (HELP)

TABLE A
ID     TERM     UNITED
1     604     LOP
1     604     MA
9     704     SC
9     603     CI
9     704     BPO
3     603     LOS
2     603     KIR
1     603     SSK
1     602     MNO
TABLE B
ID     CITY
1     (null)
1     (null)
9     603
9     603
9     603
3     (null)
2     (null)
1     (null)
1     (null)
I WANT:
ID     TERM
1     604
9     (null)
3     603
2     603
1     602
So where there is a UNITED and NO CITY then display lowest TERM.
BUT IF there IS A UNITED AND CITY then NULL (eg ID 9)
What i had:
SELECT A.ID, min(A.TERM) as TERM
FROM TABLE A, TABLE B
WHERE A.ID = B.ID
AND A.UNITED IS NOT NULL
AND B.CITY IS NULL
GROUP BY A.ID
ORDER BY A.ID
which gets me:
ID     TERM     UNITED     CITY
1     604     LOP     (null)
1     604     MA     (null)
1     603     LOS     (null)
3     603     KIR     (null)
2     603     SSK     (null)
1     602     MNO     (null)
It Does not disply ID 99999
I know why but i dont know how to ad a case statement to bypass it.
Can any one help?
Thank you.
Edited by: 927374 on 12/04/2012 23:11
Edited by: 927374 on 12/04/2012 23:13
Edited by: 927374 on 12/04/2012 23:14

I am not sure why you expect this row :
ID     TERM
1     604Shouldn't the lowest TERM for ID 1 be 602 ?
may be :
SQL> ed
Wrote file afiedt.buf
  1  with tab_a as
  2  (
  3  select 1 ID, 604 term, 'LOP' united from dual union all
  4  select 1, 604, 'MA' from dual union all
  5  select 9, 704, 'SC' from dual union all
  6  select 9, 603, 'CI' from dual union all
  7  select 9, 704, 'BPO' from dual union all
  8  select 3, 603, 'LOS' from dual union all
  9  select 2, 603, 'KIR' from dual union all
10  select 1, 603, 'SSK' from dual union all
11  select 1, 602, 'MNO' from dual
12  ),
13  tab_b as
14  (
15  select 1 id, null city  from dual union all
16  select 1, null  from dual union all
17  select 9, 603 from dual union all
18  select 9, 603 from dual union all
19  select 9, 603 from dual union all
20  select 3, null from dual union all
21  select 2, null  from dual union all
22  select 1, null  from dual union all
23  select 1, null  from dual
24  )
25  select id,
26         min(term) term
27  from   (select a.id,
28                 a.united,
29                 Nvl2(b.city, min(null), min(a.term)) term
30          from   tab_a a,
31                 tab_b b
32          where  a.id = b.id
33          group  by a.id,
34                    a.united,
35                    b.city
36          order  by a.id)
37* group  by id
SQL> /
        ID TERM
         1 602
         2 603
         3 603
         9
4 rows selected.

Similar Messages

  • Best iPad mini retna case

    Best Ipad min retna case ANY advice would help

    I like using the Khomo iPad Mini Smart Case. If you have considered buying Apple's smart case but find it to be too pricey this is the case for you!

  • When setting up my hubby's new phone to itunes, I have somehow merged the 2 itunes accounts together and now itunes is not responding to my phone and all of my info has synced onto my hubby's phone wiping all of his info and adding mine...Help!!

    I have an Itunes account already set up, when setting up my hubby's new phone to itunes, I have somehow merged the 2 itunes accounts together and now itunes is not responding to my phone and all of my info has synced onto my hubby's phone wiping all of his info and adding mine...Help!!

    If her data was not backed up or synced to something, it's gone. Sorry.

  • Will an iPad mini 2 case fit the new iPad mini 3?

    will an iPad mini 2 case fit an iPad mini 3?

    Yes, the dimensions of the iPad Mini 2 and iPad Mini 3 are identical.

  • My macbook pro's screen constantly goes dim. I have set the energy saver settings for battery to 7 mins but it goes dim if the period of inactivity is less than 7 mins. Please help.  MBP 13" OSX 10.6.8 (2011)

    My macbook pro's screen constantly goes dim. I have set the energy saver settings for battery to 7 mins but it goes dim even if the period of inactivity is less than 7 mins. Please help.  MBP 13" OSX 10.6.8 (2011)

    Doesn't sound like it.  It sounds like you're being logged-off.
    Does your Mac go through the complete Restart cycle -- black screen, gray and/or blue screen momentarily, startup chime, etc? 
    If you're not sure, do a Restart just to watch the process; the next time the problem occurs, see if it's the same.
    You need to know which it is, as these will have very different causes, and different places to look for a solution.

  • Mac app is asking me to update an app, but it does says that its with another account that is not mine, can someone help me please?

    mac app is asking me to update an app, but it does says that its with another account that is not mine, can someone help me please?

    same issue here with MacTracker 6.2 that I don't have but shw in the Update part, when clicking it asks me to log with [email protected] account first which is not mine

  • Does iPad Mini Smart Case easily get dirty?

    Hello :)
    I'm totally happy with my smart case, but one question is still interesting for me.
    Does the red iPad mini smart case (leather) easily get dirty? (For example: lay on a table, put in school bag etc.)
    Thx for your answers :)

    Depends how dirty the table or inside of yours school bag is.
    Only dirt that it comes into contact with can be transferred to the smart case. Dirt doesn't just occur.

  • After full charge i can use my macbook only for 2hrs and after 20 min my battery percentage decrease from 100% to 87% and it will happend every 20 min .. pls help me

    after full charge i can use my macbook only for 2hrs and after 20 min my battery percentage decrease from 100% to 87% and it will happend every 20 min .. pls help me

    Hi,
    How old is your MBP? how many cycle batter do have ?
    I will also recomend to use the software http://www.macupdate.com/app/mac/24141/battery-health-monitor
    to monitor battery life.
    You should be able to read everything from the software.
    Please post results.
    Regards,
    Mirek

  • I've been hearing static/hissing sounds on my speaker for my ipad mini. Please help!

    I've been hearing static/hissing sounds on my speaker for my ipad mini. Please help!

    Set the system alert to a completely different LOUD sound, like the train whistle. If the beep persists, it ain't the Mac.

  • When can i get an iPad mini Smart case?

    Anybody know When can i get an iPad mini Smart case?

    When I was in my local Apple store to get my wife an iPhone 5, I saw that hey had the iPad mini smart covers there.

  • Will ipad mini smart case discolor?

    I want to purchase ipad mini smart case but I'm worried if it would wore out and discolor like iphone leather case.
    Although it has nice looking, I don't want to spend money on a case that will not last long.
    Can anyone tell me their experience?

    It's a physical product that will endure wear depending on how you use it. No one but you can say how you will use or abuse the cover. In any case, I would rather have my cover wear than leave my iPad screen unprotected. That said, my iPad cover wore fine for over a year. Then normal signs of aging.

  • I Can't Update my Mini! Please help me!

    Hi, I recently bought a laptop, so I transferred my Ipod mini and iTunes library to that computer. My brother put a bunch of songs on the iTunes on our desktop pc, so that he could borrow my iPod and listen to his stuff; I can't seem to find a way to put the songs he downloaded on the desktop into my iPod though. I've been trying everything I can think of, I've been trying to add different folders to the library, and I also updated to iTunes 7.0, but nothing is working. I can't find a way to transfer his limewire songs into my itunes either.
    How do I put the songs from the desktop into my iPod? Help would be greatly appreciated.

    If you have Apple Care, call them and get a case number.  Otherwise, take the computer to an Apple store or an AASP.  Whichever is more convenient for you. 

  • IPod Mini Problems Please Help

    This is my second post of the type... no one replied to that so im hoping someone could help me.
    Problems:
    -Wont Update or Load Songs
    -It starts loading, gets to around the 5th song (out of well over 600) and says "Ipod Update Complete, OK To Disconnect" though nothing is on the iPod.
    -Occasionally wont restore to factory settings.
    Okay, before you suggest the five R's, ill note that ive put several MONTHS into this, and ive tried them well over 20 times in order.
    Things Tried
    -5 R's Repeatedly (as noted above)
    -updating on a friends computer (several times with no luck, same problems)
    -requested help over the phone
    -The number i called was the Apple US Help Line, which the person helped me for about an hour before he said he did not know what was up, and transfered me to the Canadian help line, where they demanded a large sum for help, which i could not pay (under 18).
    -When i first noticed the problems, I sent it in (around the end of december)and problems continued upon arrival of the new mini.
    I will also note that my sisters iPod Nano works perfectly fine, no problems, as well as my friends iPods adding songs from my computer.
    Please please help... im currently resorting to a crappy CD player that skips for my music... and have been... its starting to break me inside.
    Thank you,
    Milan

    Natalie,
    If you have your iPod set to transfer your music manually, then that “do not disconnect” message will continue to be displayed on your iPod until you manually eject it.
    You can do this by clicking on the little eject icon next to the iPod listing in the source window of iTunes, or right click on it and select “eject”. Another way would be to use the “safely remove hardware” icon in the system tray next to the clock (looks like a grey rectangle with a green arrow above it). Click on this then select your iPod. Or through Windows, select start/my computer, right click on the iPod, select eject.
    If you have your iPod set to automatically sync with iTunes, right click on the iPod in iTunes, select options and if you have a check mark in the box marked “enable disk use”, remove it and your iPod should automatically disconnect after it’s finished transferring music.
    For the iPod to automatically open iTunes, you have to have "open iTunes when this iPod is attached" checked.
    Go to edit/preferences/iPod to do this.
    If you prefer to keep the iPod set to manual transfer, look at this. In fact, the whole tutorial is a must read.
    Managing Your Songs Manually
    iPod Tutorial
    iTunes Tutorial Windows

  • When I go to update my software using the app store download, it always asks for the previous user's ID, not mine.  Please help!

    When I go to update my software using the app store download, it always asks for the previous user's ID, not mine (my IT guy at school's-I am a faculty with admin priviledges).  I have signed in as me, have set the main preferences login user as me,and everywhere on the laptop I can use my apple ID except here.  It always shows me a greyed out ID of my IT.  How can I reset this to my ID? It doesn't give me an option to change the user ID, only a link to reset password.  I reset it, but it did not change the problem.  Can someone help me?

    It's not an ID problem, it's an ownership problem.
    When someone uses their personal Apple ID to buy and download content, the content is licensed to them and has their Apple ID engrained in it's DNA. It is an anti-piracy program. And when that personal Apple ID is used to setup a new Mac, it involves the Mac itself, the shipping OS and any pre-installed apps as well.
    It's not the correct way to handle Macs that belong to a business or an institution. And had it been handled correctly they would not now be in this predictument needing a drastic remedy.

  • My Left-click on mouse is not working on mac os 10.8.2 mac mini. Please help ?

    Thank you for reading and helping out !
    All of a sudden, my left click on microsoft optical mouse stopped working. Then it worked for sometime then permanently stopped working after an hour. (its been 24 hours now). It was working fine before.
    Here is what I have tried so far.
    Tried Replacement optical mouse, which was not detected.  so can't even use a replacement mouse.. it only seems to recognize original mouse and respond to it only.
    I have turned Bluetooth off so that shouldn't be a cause.
    unplugged keyboard  and still left click on mouse not working.
    unplugged computer and all cables for more than 6 hours.. still not working...
    couldn't zap pram (for some reason being a microsoft keyboard ?? would you have proper instructions on how to to do this in windows keyboard??? )
    My Specs: mac mini 10.8.2 with microsoft ergnomic keyboard and basic microsoft optical mouse.
    i appreciate any help you would provide to get this solved!
    Thank you.

    Java for OS X 2012-006: How to re-enable the Apple-provided Java SE 6 applet plug-in and Web Start functionality

Maybe you are looking for

  • Blog Web Template

    Hi, I am working on a web template based on a blog. I built a project in visual studio using the web template feature. I am able to deploy the solution and create a site based off the blog template. However, I am wanting modify the default.aspx page.

  • Strange issue with ADF table in chrome browser

    I have ADF table which should display 23 rows, but only 20 rows are visible in chrome browser, but other browsers like IE, firefox displays the 23 rows correctly. I have used default ADF table with Drag&drop behaviour in this table. All the 23 rows e

  • How to set EOF as delimiter in Format Builder?

    I'm triying to establish the last item delimiter of a one line/record file whitch has nothing but EOF, I mean that this item ends whithout delimiter, only the file ends. How do I set an EOF as delimiter? Thanks!

  • Why iPhone only allows sync ALL contacts, not selected groups?

    THE OBJECTIVE: To back up the names and phone numbers I've manually input into my iPhone. THE MONKEY WRENCH: When I plug my iPhone 3g into my Powerbook, under the Info tab is a Contacts section. The Sync Address Book contacts box is checked, and belo

  • Sound crackly on HP Pavillion g61394sa after windows 8 upgrade

    Product name: HP Pavilion g6 Notebook PC Product number: B6J45EA#ABU Windows 8 Pro 64-bit Sound is awful after upgrage system restore not working itys ok when going to TV via HDMI Plz help