Querying on a value and using that to pull other data in the same query

I am having some issues pulling the correct data in a query. There is a table that houses application decision data that has a certain decision code in it, WA, for a particular population of applicants. These applicants also may have other records in the same table with different decision codes. Some applicants do NOT have WA as a decision code at all. What I need to do is pull anyone whose maximum sequence number in the table is associated with the WA decision code, then list all other decision codes that are also associated with the same applicant. These do not necessarily need pivoted, so long as I can pull all the records for a person whose highest sequence number is associated with WA and all of the other decision codes for that applicant for the same term code and application number also appear as rows in the output.
I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them.
DROP TABLE SARAPPD;
CREATE TABLE SARAPPD
(PIDM              NUMBER(8),
TERM_CODE_ENTRY   VARCHAR2(6 CHAR),
APDC_CODE         VARCHAR2(2 CHAR),
APPL_NO        NUMBER(2),
SEQ_NO             NUMBER(2));
INSERT INTO SARAPPD VALUES (12345,'201280','WA',1,4);
INSERT INTO SARAPPD VALUES (12345,'201280','RE',1,3);
INSERT INTO SARAPPD VALUES (12345,'201280','AC',1,2);
INSERT INTO SARAPPD VALUES (23456,'201280','RE',1,2);
INSERT INTO SARAPPD VALUES (23456,'201280','WA',1,3);
INSERT INTO SARAPPD VALUES (23456,'201280','SC',1,1);
INSERT INTO SARAPPD VALUES (34567,'201280','AC',1,1);
INSERT INTO SARAPPD VALUES (45678,'201210','AC',2,1);
INSERT INTO SARAPPD VALUES (45678,'201280','AC',1,2);
INSERT INTO SARAPPD VALUES (45678,'201280','WA',1,3);
INSERT INTO SARAPPD VALUES (56789,'201210','SC',1,2);
INSERT INTO SARAPPD VALUES (56789,'201210','WA',1,3);
COMMIT;I have attempted to get the data with a query similar to the following:
WITH CURR_ADMIT AS
      SELECT   C.SEQ_NO "CURR_ADMIT_SEQ_NO",
                        C.PIDM "CURR_ADMIT_PIDM",
                        C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
                        C.APDC_CODE "CURR_ADMIT_APDC",
                        C.APPL_NO "CURR_ADMIT_APPNO"
                          FROM SARAPPD C
                          WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
                          AND C.APDC_CODE='WA'
                         AND C.SEQ_NO=(select MAX(d.seq_no)
                                               FROM   sarappd d
                                               WHERE   d.pidm = C.pidm
                                               AND d.term_code_entry = C._term_code_entry)
select sarappd.pidm,
       sarappd.term_code_entry,
       sarappd.apdc_code,
       curr_admit.CURR_ADMIT_SEQ_NO,
       sarappd.appl_no,
       sarappd.seq_no
from sarappd,curr_admit
WHERE sarappd.pidm=curr_admit.PIDM
and sarappd.term_code_entry=curr_admit.TERM_CODE_ENTRY
AND sarappd.appl_no=curr_admit.APPL_NOIt pulls the people who have WA decision codes, but does not include any other records if there are other decision codes. I have gone into the user front end of the database and verified the information. What is in the output is correct, but it doesn't have other decision codes for that person for the same term and application number.
Thanks in advance for any assistance that you might be able to provide. I am doing the best I can to describe what I need.
Michelle Craig
Data Coordinator
Admissions Operations and Transfer Systems
Kent State University

Hi, Michelle,
903509 wrote:
I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them. You really ought to get the necessary privileges, in a schema that doesn't have the power to do much harm, in a development database. If you're expected to develop code, you need to be able to fabricate test data.
Until you get those privileges, you can post sample data in the form of a WITH clause, like this:
WITH     sarappd    AS
     SELECT 12345 AS pidm, '201280' AS term_code_entry, 'WA' AS apdc_code , 1 AS appl_no, 4 AS seq_no     FROM dual UNION ALL
     SELECT 12345,           '201280',                    'RE',               1,             3                 FROM dual UNION ALL
     SELECT 12345,           '201280',                  'AC',            1,          2               FROM dual UNION ALL
... I have attempted to get the data with a query similar to the following:
WITH CURR_ADMIT AS
      SELECT   C.SEQ_NO "CURR_ADMIT_SEQ_NO",
C.PIDM "CURR_ADMIT_PIDM",
C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
C.APDC_CODE "CURR_ADMIT_APDC",
C.APPL_NO "CURR_ADMIT_APPNO"
FROM SARAPPD C
WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
AND C.APDC_CODE='WA'
AND C.SEQ_NO=(select MAX(d.seq_no)
FROM   sarappd d
WHERE   d.pidm = C.pidm
AND d.term_code_entry = C._term_code_entry)
Are you sure this is what you're actually running? There are errors. such as referencing a column called termcode_entry (starting with an underscore) at the end of the fragment above. Make sure what you post is accurate.
Here's one way to do what you requested
WITH     got_last_values  AS
     SELECT  sarappd.*     -- or list all the columns you want
     ,     FIRST_VALUE (seq_no)    OVER ( PARTITION BY  pidm
                                    ORDER BY      seq_no     DESC
                              )           AS last_seq_no
     ,     FIRST_VALUE (apdc_code) OVER ( PARTITION BY  pidm
                                    ORDER BY      seq_no     DESC
                              )           AS last_apdc_code
     FROM    sarappd
     WHERE     term_code_entry     IN ( '201210'
                       , '201280'
SELECT     pidm
,     term_code_entry
,     apdc_code
,     last_seq_no
,     appl_no
,     seq_no
FROM     got_last_values
WHERE     last_apdc_code     = 'WA'
;Don't forget to post the results you want from the sample data given.
This is the output I get from the sample data you posted:
`     PIDM TERM_C AP LAST_SEQ_NO    APPL_NO     SEQ_NO
     23456 201280 WA           3          1          3
     23456 201280 RE           3          1          2
     23456 201280 SC           3          1          1
     45678 201280 WA           3          1          3
     45678 201280 AC           3          1          2
     45678 201210 AC           3          2          1
     56789 201210 WA           3          1          3
     56789 201210 SC           3          1          2I assume that the combination (pidm, seq_no) is unique.
There's an analytic LAST_VALUE function as well as FIRST_VALUE. It's simpler (if less intuitive) to use FIRST_VALUE in this problem because of the default windowing in analytic functions that have an ORDER BY clause.

Similar Messages

  • How do I give a letter a value and use that letter as a code througout a spredsheet?

    Hi I am trying to write a spread sheet to calculate the cost of repairing stock items. I cant figure out how to make the code = the cost, so that if somone types Hx3+Tx2+rx1 it would  = £8
    Which would mean: 3 x Hooks need replacing 2 x Tabs need replacing and 1 5cm rip needs repairing.
    SO I have made one table with the codes and the values and one table for the items and their various panels that may need repairing but I cant figure out how to make it work...?
    Can any of you help...?

    HI Mich,
    Here's an idea of the complexity of the issue, using the example in line 41:
    Issue 1: determining what is code, what is quantity, and how many items are in each cell.
    In the first cell, the formula has to determine, from the text string "Rx1 rx3" that:
    There are two items. Possible to do this by counting the spaces and adding 1, or, assuming ALL parts in the cell will contain a x sign, by counting the "x" characters..
    The first letter is code. But the code could also be the first two letters, or the first two letters plus a number (eg. WP5) or the first two letters plus the next two characters (eg. WP11). Other code lengths may also be possible. The length of the (first) could be determined using SEARCH to find the first x. Subtract 1 from that to determine the number of characters in the code, then use LEFT to extract the code from the formula.
    =LEFT(B2,SEARCH("x",B2,)-1)
    Now that the code has been extracted, that formula becomes the first argument of the VLOOKUP formula from the previous post, used to find the price of that item:
    VLOOKUP(LEFT(B2,SEARCH("x",B2,)-1),Price List :: B:C,2,FALSE)
    Next, the price must be multiplied by the number following the x. That number must be extracted. Assumption: The number is a single digit, between 1 and 9, inclusive. We can use MID:
    MID(B2,SEARCH("x",B2,)+1,1)
    =VLOOKUP(LEFT(B2,SEARCH("x",B2,)-1),Price List :: B:C,2,FALSE)*MID(B2,SEARCH("x",B2,)+1,1)
    The result above gives the cost for repairing the large rip in B2
    Next, if there is more than one type of repair to be done, the process above must be repeated with a new twist: This time we're looking for the second repair item in B2. The marker is a space, so we'll need to add a SEARCH for the first space, and use that as the starting point for both SEARCH functions in this section.
    Then the whole process (with another SEARCH added to each set) must be repeated for the third (possible) code and number in the cell.
    Repeat 7 for as many items as could be included in this cell.
    We don't know how many items will be recorded in each cell, so we have to allow for a maximum and provide some means of making the formula quit when there's nothing more to be done. This could be an IF, depending on the count of "x" or " " in the cell, or an IFERROR that would trap the error caused by searching beyond the last space. Whatever we used would need to be added to each iteration of the last formula shown above.
    As you can see, this quickly becomes a bit unwieldy, and a reason for my earlier suggestion to set up pairs of columns for each repair item.
    Regards,
    Barry

  • Can't connect and use 2 Store.E Canvio HDDs at the same time

    Hi there,
    I have 2 Store.e Canvio devices: 2TB and 3TB respectively but, it looks like I can't connect/use them at the same time, as if I do, one of them (the lastest I have connected), becomes inaccessible ("denied access").
    If I disconnect the first device I connected, the second one, starts working,,,
    Is a weird issue,and I can't find anyone experiencing something similar...
    Any idea how could it be causing this, and/or how could I solve it?
    Thanks

    Im wondering if the same problem appears using another computer or additional USB hub with an additional power supply.
    From my point of few this issue could be related to low power provided by single USB port.
    Both HDDs seem to support the USB 3.0 standard.
    The common USB 2.0 port provides 500mA and USB 3.0 requires 900mA
    So this means that two USB devices connected simultaneously would use 1800mA which might be too much for the notebooks USB ports

  • I installed itunes on my hp netbook.  Opening items for the first time, the user agreement does not show an "accept" button to accept the agreement and use itunes.  Have reinstalled twice with the same result.

    Is itunes compatable with HP netbook?

    If the netbook has less than 768 dpi vertical resolution, the "Accept" button will be displaying off the bottom of the screen. (I'm afraid, if so, you'll run into similar trouble when trying to make preferences changes.)
    With any luck, the "accept" button although not visible on your system might be the active one. If you hit your enter key does the setup proceed beyond the liscensing agreement?

  • BExAnalyzer: Multiple use of the same Query in a Workbook - Command Button

    Hy Gurus,
    in my Workbook I have in Sheet 1 one Analysis Grid, defined as DP_1
    in Sheet 2 it is an other Analysis Grid defined as DP_2
    Both Data-Provider refer to the same technical BW Query.
    If I add a Button (from the BEx Toolbar) and try to refresh the first query (with commands: PROCESS_VARIABLES and VAR_SUBMIT) both Queries will be refreshed with the same variable value, even if i mention "DP_1" as Data_Provider in the button.
    But I don't want, that the second query is been refreshed too (with the same variable value).
    In the workbook Settings, I already checked on: Allow refresh Function for Individual Queries.
    Can anybody help?
    Regards
    Klaus

    It is not a solution to copy the query. We will need this feature for about 50 Workbooks/Queries and so it is the problem to keep the copied queries consistent
    If I refresh the Queries manual with the the "Change Variable Values" Button I get a pop-up with two fields where i can input two different values - here it works.
    Can I achieve the same with the command buttons?
    The definition of the first command button is like this:
    Name                       Index     Value
    DATA_PROVIDER     1           DP_1
    CMD                           1          PROCESS_VARIABLES
    SUBCMD                    1          VAR_SUBMIT
    Command Range: A2:C5 (there is the Name, Value, Sign and Operator of the Variable).
    The second command Button:
    Name                       Index     Value
    DATA_PROVIDER     1           DP_2
    CMD                           1          PROCESS_VARIABLES
    SUBCMD                    1          VAR_SUBMIT
    Command Range: A12:C15 (with a different Value of the Variable).
    If there is one query in the workbook it works fine, but not for two queries, even if I change the Index of the second button to 2.
    Thank you for your hints.
    Regards
    Klaus

  • Download iOS 8 once and use it to upgrade all iPads in the network

    Is it possible to download iOS8 only once and use it to upgrade all iPads in the same LAN? 
    I tried the following methods and they are just not working:
    1. Connect an iPads Mini with Retina Display to the iTunes on Mac.  I chose Download Only. Once downloaded the iPad Software Upgrade, I upgraded the connected iPad to iOS8.  Then I connect another iPad (used to be on another Mac) to the same iTunes.  I had to download iOS 8 again.  It's not using the same downloaded iOS 8 file.
    2. I turned on the Caching Service (not Software Upgrade Service, i.e. for Mac Software) on the Mac Mini Server from the Server app.  I then repeat step 1 above and got the same result.  It seems that the Caching Service does not cache the iOS 8  Software Upgrade like what it does for other apps.  (I think I may need to use some Apple Scripts but I have no such experience.)

    Ivan H wrote:
    It's for the family.  Every member has 2-3 iOS devices to upgrade.
    I agree with Csound on that, a family, even with a lot of devices will have to individually update.  There are enough nuances in the iOS for different devices that you need to download for each.  If you had 200 iPad 2's then there might be an enterprise way...but not a family with a mix of devices.

  • Using join and batch reading in the same query

    Hi,
    I wonder if it is possible to use "Joining" and "batch reading" in the same query.
    For example I Have
    A -> 1-1 B
    A -> 1-1 B
    B -> 1-M C
    This is the case where I have two separate 1-1 relationships to the same class B from A. Toplink 10.0.3 can manage it nicely through joining.
    Now, I would like to read a set of As (with its 2 Bs) and all Cs for each B.
    It seems that the following configuration does not work:
    A -> 1-1 B (use joining)
    A -> 1-1 B (use joining)
    B -> 1-M C (Batch read)
    Any help would be greatly appreciated
    Tony.

    James,
    Would you be so kind to look at the following code?
    Am I formulating it correctly to achieve my desired behavior?
    Trip.class -> 1-1 PickupStop
    Trip.class -> 1-1 DropoffStop
    PickupStop and DropoffStop extend Stop and use same table (STOP)
    Stop -> 1-M StopEvents
    I would like to fetch all Trips, with their Stops and all StopEvents in 2 queries:
    1. Trip joined with Stop
    2. Batchread StopEvents
    Code:
    ReadAllQuery raq = new ReadAllQuery(Trip.class);
    Expression qexp1 = new ExpressionBuilder();
    Expression qexp2 = new ExpressionBuilder();
    raq.addJoinedAttribute("pickupStop");
    raq.addJoinedAttribute("dropoffStop");
    raq.addBatchReadAttribute(qexp1.get("pickupStop").get("vStopEvents"));
    raq.addBatchReadAttribute(qexp2.get("dropoffStop").get("vStopEvents"));

  • Hi! can any1 pls let me know how to create a look up table in labview and use that in the vi.

    hello !
    i have no idea how to build a lookup table(as v use in microcontroller) in labview and use that in vi.pls help me
    txs
    nitin
    Solved!
    Go to Solution.

    If the lookup table is always going to remain the same (e.g. a character generator or something similar) you can place the values in a 2D array constant on your diagram, with the input value as one column, the equivalent as the other. When you need to perform the lookup you use an index array to return all the values in the "input column", search it using "search 1D array" and use the resulting index number to index the other column's data. If the values may change, then it would probably be best to load an array control with your equivalent values from a file.
    P.M.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • I don't have a wireless printer, and want to print things off of my iPad.  I know that I can use the iPad Camera Connection kit to connect USB devices like keyboards and I am wondering if I could do the same with a USB printer.

    I don't have a wireless printer, and want to print things off of my iPad.  I know that I can use the iPad Camera Connection kit to connect USB devices like keyboards and I am wondering if I could do the same with a USB printer.

    I don't think you can connect a printer since you won't have the printer drivers. I use FingerPrint from collobos.com to print to my non-AirPrint printers.

  • How can I move my old iPhoto library into a Referenced Library format and use that as my default?

    Hi, I have been using iPhoto for photo management where all the jpegs have been living, in organized events by date and subject for some time. I recently upgraded to aperture and am using the same iPhoto library. The issue I have is that I use Carbonite for my cloud back up and I am able to look at the pictures I have on my PC with the same folder organization I have them on my PC hard drive. This is apparently not possible for iPhoto library. The only way to access a picture on the iPhoto library in the cloud is to go through the master and hope you can find the specific picture since they are not organized in a comprehensible manner (like events or folders) in there.
    So the only solution I can think of is to move the current iPhoto library to a referenced image library and use that as my default library from now on. This way I get cloud access and the events will hopefully turn into folders with dates and subjects that I can continue to keep organized to satisfy my OCD tendencies.
    So the question I have is that:
    1. How can I make a reference Library for Aperture/iPhoto?
    2. How do I move the current library to the Referenced Library in an Organized manner? My wish list would be a series of folders labeled with the date and the subject, like I have in my iPhoto library right now.
    3. If there is any alternative, your suggestions and recommendations would be much appreciated.
    My computer: Mac Mini (Mid 2012), Lion, 16GB RAM.
    Thank you kindly,

    Or is there a way to go through aperture to make a new reference library that I can move the masters into later?
    you do not move the masters into a references library - you turn your current library into a referenced library.  As Terence Devlin said:
    File -> Relocate Masters
    What you should set up:
    Select a folder, where you want to store your referenced files - probably on an external drive.
    Decide on a hierarchical folder structure inside this folder - that is completely up to you.
    Select a project from your library and use the command "File -> Relocate Masters/Originals" to move the original image files to the folder where you want to go them to. Only take care not to send two projects to the same folder.
    Alternatively, if you do not care about the folder structure Aperture will use, select all images at once from the "Photos" view and let Aperture decide how to assing the folders - in the "Relocate Originals" dialoge you can specify a subfolder format.
    Regards
    Léonie

  • I have bought a new airport express and using it with my macbook (iTunes 10.2.2). I have joined an existing network for internet in my home and with that i am trying to play the music via itunes but there is audio dropouts every 60 secs or so. any soln ?

    I have bought a new airport express and using it with my macbook (iTunes 10.2.2). I have joined an existing wireless network for internet in my home and with that i am trying to play the music via itunes but there is audio dropouts every 60 secs or so. I am using a set of speakers from kenwood connected to the airport express. The operating system on my macbook is mac os X 10.5.8. i am sure it is not a problem of streaming music online because i have even tried playing music which are stored in my macbook.
    Is there any problem with the setting in itunes or quicktime ? Kindly reply...... I am waiting for your valuable suggestion.
    Thank you a lot in advance.

    I am shocked to have found this same AX audio dropout problem starting TODAY, every few seconds the audio just drops for a couple seconds and then resumes:  Latest software versions of everything.  No iPad, iPhone or Touch.  Internet hardwired to D-Link DES1105 (1000baseT Switch) hardwired to new 80211N AX, AX optical to stereo, AX Wi-Fi internet to basic 1st-gen MacBook operating at 80211G, and an older 'G' AX extender at the far end of the house, away from all this.  The MacBook streaming iTunes is usually 12 feet from AX.  I've used this setup for years of trouble-free AirTunes / Airplay until today.  Today I also found 2 very reliable fixes and 1 way to force a dropout, but first, I read some posts and tried ALL following settings one-at-a-time and restored them ALL because NONE of them helped:  Turned off IPV6.  Streamed to multiple speakers 'Computer' and 'AX' (restored to just AX).  Turned off 'Ask to Join new (WiFi) Networks'.  Turned off Bluetooth (can't live without Magic Trackpad, so glad that wasn't it).  Here's my discoveries:  Lo and behold, each time I click the Airport icon in the Menu (you know it shows you've got 4 bars from AX) when the status switches to 'Looking for Networks' for a second it CAUSES the AX audio to drop out for a couple seconds (it never did that before today.)  iTunes still playing, streaming, AX laser still lit, but the 'PCM' light on stereo and the sound GOES OUT EVERY time I click the Airport icon in the menubar, just like the regular, annoying dropouts.  So, to reduce traffic I quit Safari (3 tabs, no streaming, just Gmail, Google, and Netflix browsing).  Lo and behold, the dropouts stopped altogether.  No other Web apps going (not iTunes Store, Genius, Ping, nothing), so I launched Chrome to the same 3 tabs and the dropouts HAVE NOT RETURNED.  That's right, not only did simply QUITTING SAFARI cure it, and Chrome doesn't contribute to it, but I can demonstrate it just by forcing my Airport to re-scan.  Works for me, written using Chrome.  The other reliable fix is to hardwire MacBook to the Switch.  This is obviously not ideal, but Airplay audio doesn't drop out over Ethernet.  Also, in all my tests, it made no difference whether iTunes did the streaming, or Airfoil did.

  • If I already have an Airport Express Base Station, can i hook an external hard drive into it's USB port and use that hard drive with Time Machine?

    If I already have an Airport Express Base Station, can i hook an external hard drive into it's USB port and use that hard drive with Time Machine?

    No, and that shouldn't be done with an AirPort Extreme or Time Capsule.
    (66017)

  • Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts Layer Comps to PDF"? And how do I get them to look the same?

    Why do vector lines appear different in my Photoshop document compared to the PDF that was created using "Scripts > Layer Comps to PDF"? And how do I get them to look the same?

    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand, such as your platform (Mac or Win), exact versions of your OS, of Photoshop and of Bridge, machine specs, what troubleshooting steps you have taken so far, what error message(s) you receive, if having issues opening raw files also the exact camera make and model that generated them, etc., someone may be able to help you.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • HT201365 hello sir i purchase second hand iphone4s now my iphone ask for activation with id and password i contact with previous owner and use that id and password but that also not work what i do ola help me

    hello sir i purchase second hand iphone4s now my iphone ask for activation with id and password i contact with previous owner and use that id and password but that also not work what i do ola help me i try all other method restore ' upgrade etc but none work plz say what i do if u find some solution tham msg me on [email protected]

    First, we're not Apple here (Apple does not participate in this forum).  We're only users like you.
    The previous owner has not given you the correct ID and password for you to use.
    If the iphone has iOS version 7, then read through the following...
    http://support.apple.com/kb/HT5818

  • Hello sir i purchase second hand iphone4s now my iphone ask for activation with id and password i contact with previous owner and use that id and password but that also not work what i do ola help me i try all other method restore ' upgrade

    hello sir i purchase second hand iphone4s now my iphone ask for activation with id and password i contact with previous owner and use that id and password but that also not work what i do ola help me i try all other method restore ' upgrade etc but none work plz say what i do if u find some solution tham msg me on
    iPhone 4S

    oenkz33 wrote:
    this does not help at all for the second owner, after making the first owner id with careless, sorry for my english ...
    Careless? Possible, but unlikely. Most likely the phone was stolen from the first owner. It would be a VERY careless iPhone owner who did not erase their personal information from a phone before selling it, and to do that it is necessary to disable Activation Lock. In most places in the world knowingly using stolen property is a crime, so the fact that the phone doesn't work may be the least of one's risks.

Maybe you are looking for