Select a count using the last entry of a table

I have a huge project for which I am trying to learn some PL/SQL.
Context:
Entry gets put into the Orders table. What I want to do is create a trigger( out of scope for this question) that takes the last entry's product ID number and performs a count of all the PID's that match it. Then I want to compare that number with a number in the ProductTransaction table.
I.e.
Orders ProductTransaction
OID TID
PID PurchaseCount
o_TID Price
etc.....
Last entry that gets put in contains
OID PID TID
4 100 2
ProductTransaction
TID PurchaseCount Price
2 10 100.00
What I want to do is if the last entry into the Orders table was the OID 4 then I want to count all PID=100 and determine if the PurchaseCount has been reached yet.
The only thing I can think of is the following, but it doesn't ensure that the last PID is what we are counting:
declare
v_countpid number;
begin
select
count(pid) into v_countpid
from
orders
where OID = (select last(oid) from orders);
dc
Im thinking something like the above which populates the v_countpid
and then taking another variable which is a select into which takes the last TID entered and comparing them in an if statement of some sort
Let me know your thoughts on this....

They you both for your replies. I was pushing myself to stay up late last night and I guess I didn't included everything.
Here it goes.
The concept is to have someone buy a product lets say at 10 dollars and it will take 10 other people for you to finally get your product released to you.
So when I purhcase PRODUCT A and put the entry into the orders table it will be something like this:
OID = 1
PID = 101
TID = 2
TIMEOFPURCHASE=<timestamp>
etc........
Now once that is entered into the table I am going to have a trigger as an after insert that will count the total PID's in the table that match what I just put into it, as in this case it was PID=101. The count of PID=101 will then be matched against the ProductTransaction PurchaseCount field to determine if that product should be released to the person with the lowest timestamp.
So....
ProductTransaction
TID=2
PRICE=$10
PurchaseCount=10
ORDERS
OID PID TID TOP
1 101 2 3 am
2 101 2 5 am
3 30 1 12 pm
4 101 2 4 pm
Example. The last entry was OID=4 so it will count up the number of PID=101 and then that number is compared against ProductTransaction purchase count. If hasn't exceeded then nothing happens. If the number is matched then OID=1 is moved into the shipping table for processing.
Let me know if this still doesn't clarify, or if there is a better way to do this....

Similar Messages

  • How do you select all paragraphs using the same style in Pages 5.2?

    I'm trying to find how to select all paragraphs using the same style in Pages 5.2 without any success.  I writing a book and I need to able to adjust all my paragraph styles globally.  I see how upgrade my paragraph style when I do something new, but not how to revert back to the orginal template.
    For example, in my custom template for my book I have 12 font for a review questions paragraph style.  I changed the font size for all this paragraph style to 18 font.  Now I want to change it back to size 12 font.  But I have this paragraph style at the top and bottom of my document.  How to I select all of my review questions style so I can make the font change to all at the same time? 
    I just upgrade to Pages 5.2 from Pages '09. 
    Thanks for the help,
    Rob

    The Pages User Guide might help here.
    Better to post your topic in the Pages designated community > Pages: iWork: Apple Support Communities

  • How do I do to use the same appleid on all my devices, I want to use the last one I have on my Ipad mini, do I deleta the one I have on my Iphone and reeinstall it with the Id I use on my Ipad..?

    how do I do to use the same appleid on all my devices, I want to use the last one I have on my Ipad mini, do I deleta the one I have on my Iphone and reeinstall it with the Id I use on my Ipad..?

    Hi john,
    Yes, you would sign out of iTunes & App Store: Settings>iTunes & App Store, click on the Apple ID, click on Sign Out. Then sign back on with the new Apple ID. Also, if you have an iCloud account with the other Apple ID, you would delete that iCloud account, and then sign on with your new ID: Settings>iCloud>Delete Account.
    Cheers,
    GB

  • Problem with JFMERGE using the last set of data on all form sets

    b Here is the scenario...
    I have a file of data in character delimited format. Each record needs to produce the same set of forms. I used the Visual Transformation Editor to define the field nominated data file, including the ^form statements. The transformation agent processes the file of multiple records just fine. I get a file from JFTRANS that contains the set of data & form statements repeated for each record in the file.
    Great so far.
    b Here is the problem...
    Unfortunately, the print agent is repeating the same set of data on every copy of the set of forms that is printed. It uses the data from the last set of forms to be printed.
    b Additional information...
    For ease of building the field nominated file by our custom client program we have standardized on using GLOBAL fields. Therefore, our DAT files contain all the ^global declarations with all the necessary ^form statements at the end. I used the transformation editor to build the same type of file. Therefore the file going to the print agent looks like:
    ^global name1
    data1
    ^global name2
    data2
    ^form form1
    ^form form2
    ^global name1
    newdata1
    ^global name2
    newdata2
    ^form form1
    ^form form2
    The printed result puts "newdata1" & "newdata2" on both sets of form2. Strangely, the correct data values are showing up on both sets of form1.
    The only difference between the two forms is that form1 is not defined with the fields as global where form2 does define them as global. I removed the global flag from form2 but that didn't change anything.
    I think I know what is occurring. JFMERGE is putting the data elements into the global dictionary and when the same name is in the file the latest data value ends up in the dictionary (thus all the forms print using the last data put into the dictionary). I certainly didn't expect this. I thought it would load the dictionary and print the first set of forms, then reload the dictionary and print the next set of forms. At least that is the way I see it occuring based on the order of things in the DAT file. Based on what is occuring it appears that JFMERGE reads the whole DAT file, building the dictionaries and then processes all the ^form statements.
    b My request for help...
    Does anyone know what I can do (such as insert some command) to get the correct data on the forms?
    It looks like using a fixed record format might do the trick but that isn't an option at this time. As things are right now it looks like I'm going to have to take the data file apart, and make lots of files with one line of data per file.
    I have a time deadline to get this printed so if there isn't a way to make JFMERGE operate as I expected it looks like I'll be doing this by hand. Fortunately, there are only 250-300 data lines. Future jobs could have thousands of data lines so if there isn't a way to do it with a multi-line data file I'll have someone create a program for splitting the original file up (and adding the ^job line).

    We don't use subforms so some of what you suggest isn't effective for us. Our forms are a duplication of the paper forms and are not dynamic. We design each form separately and our custom filler software (that builds the DAT file) uses a database with the required forms for each print job defined within it.<br /><br />Since we don't have subforms, our simple method of printing is to declare as GLOBAL all the unique fields used on all the forms to be printed followed by the ^form commands. It was a simple & straightforward method for us to do better than 500 print jobs over that past couple of years. In addition, our custom filler software can easily build the DAT files.<br /><br />Because I need to manually declare all the ^form statements my experience with using ^field is that the form must be declared followed by the appropriate field commands (repeat for all the forms).<br /><br />i <many hours later I continue typing this post><br /><br />Taking the original Transformation Definition File and customizing it for how things need to be when using ^field commands was a time consuming experience (and a learning one). It did the job as I needed but it is an experience I don't want to repeat. There has got to be a better way of building the TDF properly. I'm definately leaning towards a program to split the file into multiple files.<br /><br />Here is what I went through...<br /><br />I did all the editting using Notepad. I changed all ^global to ^field. Then I had to remove the #comment lines. Next was to find any references to fields that had to be global to the top and chang ^field to ^global. Then it was moving the fields around so they were underneath the appropriate ^form statement. Then, since one of the forms was multi-page I had to add the ^page command and sort the fields so they were under the correct page. That was followed by duplicating fields that are used on multiple forms or multiple pages. Then I discovered that the print agent won't do ^page unless "inline processing" is turned off (I did not want to specify the page name as it could change over time) - so I added "^inline off" in front of every ^page. Finally it was removing unecessary field references so the log file would be clean.<br /><br />For those that are interested, the following is an example of my final file. <br /><br />^global nameA<br />data<br />^global nameB<br />data<br />^form nameX<br />^field name1<br />data<br />^field name2<br />data<br />^form nameY<br />^field name1<br />data<br />^field name3<br />data<br />^inline off<br />^page<br />^field name4<br />data<br />^field name1<br />^inline off<br />^page<br />^field name5<br />data<br />^field name6<br />data

  • I Use the last FCX but  I have a prob when I export (share) to dvd the result is over 4GB for a single DVD is about 6 to 9 Gb for a short film of 1h so what can I do to fix this

    I Use the last FCX but  I have a prob when I export (share) to dvd the result is over 4GB for a single DVD is about 6 to 9 Gb for a short film of 1h so what can I do to fix this thnks

    These "Share" files are accessed and used by the Create Disc app.
    Create Disc is buried in the FCP X package.
    Applications>FCP X>Show Package Contents>Contents>Plugins>Compressor>Compressor Kit.bundle>Show Package Contents>Embedded Apps>Create Disc
    I'm wondering if having the Compressor Application on a Mac makes a difference to having just FCP X on a Mac and the use of the Sharing feature.
    I have Compressor loaded and find that DVD and Bluray burns from Share without any glitches as some are experiencing.
    Al

  • I am unable to select a colour using the swatches

    I am unable to select a colour using the swatches, I have a greyish line under the colour I am trying to select and the colour I am trying to use will not highlight - this is a new problem, as it has been working fine - I have pushed something so how do I undo it? Please help, this is very frustrating

    Thank you, the step where I went to tools, options and then selected a product for the application worked. It was a problem with .pdf files. I don't understand how all of a sudden it changed from what had worked all along, but, I changed it back from xps viewer to adobe and all is working fine.
    I appreciate your help!

  • I am having a problem changing a color in a selected area. Using the Quick Selection tool I am able to select the area I wish to change. Using the Brush tool, color, color mode and click drag in my selected area, nothing happens, no color changes.   I hav

    I am having a problem changing a color in a selected area. Using the Quick Selection tool I am able to select the area I wish to change. Using the Brush tool, color, color mode and click drag in my selected area, nothing happens, no color changes. I have viewed some videos and read numerous articles but haven't found the one to help me. Please point me in the best direction. Thank you Vincent TC

    For the sake of clarity and to save people time, Todd is asking about the behaviour of the Patch tool when using it to repair the area next to the young lad's head.  Todd gets a blurred dark tone pretty much regardless of the options he uses.
    IMO that's what I would expect to happen because of the close proximity of the other image elements i.e. the lad's neck and the strong lines of his shirt.  I would not choose to use the Patch tool in this situation.  Content Aware Fill makes a better stab at it. 

  • Having trouble importing individual songs on a CD.  Instructions say to select/deselect songs using the check marks by song titles, but they are not there. never had this problem in older versions.  Help Please

    having trouble importing individual songs on a CD.  Instructions say to select/deselect songs using the check marks by song titles, but they are not there. never had this problem in older versions.  Help Please

    Are you saying that the tick-box shown in my screenshot, isn't there? (Yes, this is iTunes 11 - I've turned on the sidebar and the Menu bar. So you can see, this is a CD in my drive that we're looking at.)
    If it isn't, go to Edit/Preferences/General and turn on the tick-box box
    You can show the Menu Bar (with Edit on it) by using CTRL + B

  • When entering login's, Firefox shows the last entries.

    Whenever I am asked to log into a secure sight, Firefox shows the last entries entered; ie, when I log into Yahoo, all I have to do is enter the first letter and it shows the last 6-8 logins. I feel that this is a security issue. I don't want others to see my login's. Explorer does not do this. How do I turn this off?
    == This happened ==
    Every time Firefox opened
    == always??!

    Tools > Options > Security: Passwords: "Remember passwords for sites"
    Tools > Options > Privacy > History: "Remember search and form history"
    See:
    http://kb.mozillazine.org/Deleting_autocomplete_entries
    http://kb.mozillazine.org/Password_Manager

  • Unable to delete last entry in Custom table

    Hi,
    I have one custom table which allows only some specific entries to be maintained in the table.I have used a standard table as a check table for dis.I found no issue while maintaining entries in the table.But when i try to delete the last entry in the table i get the message "No entry exist".Long textNo entries were found when importing data from the database.
    Kindly help.

    Hi,
    If it is not possible through table maintainence then write a small Z program to delete the entries in devlopment system and then if then if you want you can transfer those to other systems.
    delete from ZTABLE where {give your condition for the last record}.
    Regards,
    Sandipan

  • How to tracke the new entries in database table ?

    Hi,
    How to tracke the new entries in database table ? is there any FM or report is there to check it ?
    regards
    vishnu

    Hi Vishnu,
    u can write a report program for this and in that use the event  :
    AT NEW <field-name> ( use primary key)
    your statements
    ENDAT
    for eg.
    loop at itab ( herfe itab must be of type of table for which u want to track new entries)
    at new matnr
    write:/ new record
    endat
    endloop.
    schedule this report in background to run in every 5 or 10 mins as per your requirement and hence changes can be tracked.
    regards
    Vinod

  • Check what is the last operation for a table

    Hi expert,
    I need to check what is the last operation for a table ? ( such as insert/delete/truncte.......), will show me the function or sql to get that?
    Many Thanks,

    hi,
    please take a look at this link
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1590655700346557237
    regards,

  • Mismatch in last entry in OJDT table and Nextval in series numbering setup

    Dear Support Team,
    We are getting FIRST DEFINE THE NUMBERING SERIES IN THE ADMINISTRATION MODULE ERROR ON ADDING ANY DOCUMENT.
    We checked for authorisation , group and posting periods. Everything in it's place.
    There is a mismatch in the last transid of OJDT table and the Nextval generated in document numbering series setup.
    How do we correct this.
    Any help would be greatly appreciated.
    Thanking you
    Pradnya

    Hi,
    We solved it by locking the erroneous series and by creating a new one. But your suggestion was more right and practical.
    Thanks for the valuable suggestion. We will keep this in mind.
    Thanking you
    Pradnya

  • Can I use the the measured time between the first count and the last count in a fixed time window in order to increase the accuracy of a quadrature velocity measurement?

    I am measuring velocity using a linear encoder. Resolution is 40microns, sample frequency is 1MHz and the real velocity is oscillatory in nature with an amplitude of 200 to 400 mm/s with a freq of about 1Hz. We use a 5ms fixed time window to measure velocity. The quanization error for this is 8mm/s. Can I get rid of the quatization error by somehow measuring the exact time from the first pulse to the last pulse in the measurement window?

    There is probably a way to do it, but it it may be easier to use an X-series board for the job.   They support a new counter capability for count reset on a digital edge without needing to be configured in encoder position mode.  I am not sure exactly how that feature's been implemented however, so maybe it won't make things easier after all.
    The plan based on the hoped-for behavior: 
    1. Configure an X-series counter for pulse generation based on "ticks" of your clock channel.
    2. Set both initial delay and low time to the critical # of ticks.
    3. Configure for count reset on a digital edge (if possible in pulse generation mode)
    4. Configure the count reset value to be the critical # (or possibly 1 less, if possible in pulse generation mode)
    5. If you want the output to remain high indefinitely, configure the counter task to use its own output as a
    pause trigger, and pause while high.
    The way pulse generation works is to preload a # of "low time" ticks into the count register.  Then every source edge will decrement the count.  When the count reaches terminal count (0), the counter's output is toggled (or can be configured to pulse).  The register is then loaded with the # of "high time" ticks and the process continues.
    You would be perpetually interrupting the count-down process as long as you got your triggers in time.  The count would keep getting reset to the # of low counts, keep decrementing toward 0 without reaching it, and so on.  If ever you did reach 0, the output state would toggle high, then the high state would prevent subsequent clock signals from decrementing the count.
    You can conceivably do a similar thing with a 6601, but I'm pretty sure you'd need 2 counters working together to get it working.
    -Kevin P

  • When I have selected multiple paths using the pen tool, I can't make a selection out of them all, but only of the last one I created.

    I want to make a selection with both paths in the selection. But it's only allowing me to select one, if I try both the paths just dissapear.

    Similarly to what @JJMack said, if you use the direct selection tool (shortcut: A), you can either select all of the paths, or select a blank area of the canvas (which will deselect all paths) and then selecting the 'convert path to selection' button should convert them all simultaneously.
    This is one of several bothersome changes to the path selection functionality in CC.

Maybe you are looking for

  • Apple iTunes 10.0.1 = BSOD in Windows 7

    Okay! I always upgrade to the latest version of software, chiefly as a test bed for others with whom I consult. I have been running Windows 7 since it was released (well before actually ). I have never ever had a BSOD for any reason on ANY of my Wind

  • Embedded fonts not working in Air for ios

    hi am building an ActionScript mobile project 4.6 for ios and want to use embedded fonts for my app. we are using the swf method for embedding the fonts , after loading the xml and even got the embedded resourses from swf , the output is not showing

  • CS5 XML/HTML Export of images

    Hi, I have to export a catalogue via XML to get it processed by our CMS. As well I also need all the pics iside the INDD for web use. The export of the tagged items weorks perfect, including the formatted images. BUT: All pics come in their printed s

  • Displaying JTable (AbstractTableModel) rows based on radiobox criteria

    hi, Would appreciate some pointers as to how to do this ... I have a AbstractTableModel that needs to display rows depending on which radiobox criteria is selected. There are only 2 columns in the JTABLE: (1) categories (string) (2) register interest

  • Azure SQL server v12 upgrade remaining time.

    I'm upgrading SQL server to v12 to be able to utilize S3 performance level. Upgrade is running for 28 hours and still not completed. Actually, info in the portal said that it takes up to 24 hours. Is there any way to determine how much time is needed