Find the same amounts

Hi All,
I have this sample data:
create table sampleTable(
sample_id number,
sample_fy number,
sample_amt number
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(1, 2003, 25);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(1, 2004, 10);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(1, 2005, 10);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(1, 2006, 46);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(2, 2003, 5);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(2, 2004, 12);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(2, 2005, 10);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(2, 2006, 6);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(3, 2003, 75);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(3, 2004, 13);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(3, 2005, 13);
insert into sampleTable(sample_id, sample_fy, sample_amt)
values(3, 2006, 26);
How can I find the rows with same amounts (amt) for the same sample_id and years between 2004 and 2005?
The result should be:
sample_id
1
3
I try lead, but it is comparing rows from different sample_id as:
SELECT sample_id, sample_fy, sample_amt,
       LEAD(sample_amt, 1, 0) OVER (ORDER BY sample_id, sample_fy) - sample_amt AS my_diff
       FROM sampleTable
       WHERE sample_fy between 2004 and 2005;
Any ideas?
Maybe is another function that I can use.
Thanks!

Hi,
I would use GROUP BY:
SELECT    sample_id
FROM      sampletable
WHERE     sample_fy  IN (2004, 2005)
GROUP BY  sample_id
HAVING    COUNT (DISTINCT sample_fy)  = 2
AND       COUNT (DISTINCT sample_amt) = 1
This does not assume that there will be esxactly 1 row for each combination of sample_id and sample_fy.  A given sample_id may be missing one year or the other (in which case it will not produce any output), or there may be multiple rows per year (in which case, the sample_id will be chosen only if all they are all equal.  I assume sample_amt can not be NULL).
If you want to use LEAD, add a PARTITION BY clause:
SELECT  sample_id, sample_fy, sample_amt,
        LEAD(sample_amt) OVER (
                                PARTITION BY  sample_id    -- This line added
                                ORDER BY      sample_fy    -- No point including sample_id
                             ) - sample_amt AS my_diff
       FROM sampleTable
       WHERE sample_fy between 2004 and 2005;
"PARTITION BY sample_id" means that a separate computation will be done for each group of rows that has the same sample_id.

Similar Messages

  • Time Capsule backs up the same amount several times

    Right now I'm using my laptop and for the past 3 hours, my Time Capsule has backed up 2.3GB. I'm just surfing the web!!!!. No idea of why it backs up the same amount while doing nothing

    Welcome to the discussions!
    Suggest that you download Time Tracker to find out what is taking up the space on your backups. Depending on how much data you have on your Time Capsule, it may take 5-10 minutes for everything to load the first time you run the program. You will be able to see exactly what is backed up on each run.
    May be a program like VM Fusion, Entourage, Aperture, and others that backup their entire database whenever any small change is made. If that's the case, you can exclude that program from Time Machine backups and do this manually.
    If you don't really need to backup each hour, you might want to take a look at Time Machine Editor to allow you to schedule backups whenever you like.

  • I deleted the pre-installed iPhoto app from my iPhone 5s by mistake. And I can't find the same app in the App Store. How do I recover it?

    I deleted the pre-installed iPhoto app from my iPhone 5s by mistake. And I can't find the same app in the App Store. How do I recover it?

    iPhoto for iOS is no longer being offered by Apple and has been replaced by the Photos app. It is not compatible with iOS 8.  This Apple document may help:  Migrating from iPhoto for iOS to Photos on iOS 8 - Apple Support

  • On my Iphone, I have an app called Voice memos where I can record someone talking or signing. I try finding the same on my Ipad but can't find it. Does it exist on Ipad?

    On my Iphone, I have an app called Voice memos where I can record someone talking or signing. I try finding the same on my Ipad but can't find it. Does it exist on Ipad?

    No, but there are plenty of Apps which will do this.
    Se this one for example:
    https://itunes.apple.com/us/app/voice-memos-for-ipad/id364295267?mt=8

  • Should all memory slots on my imac have the same amount of memory

    should all memory slots on my imac have the same amount of memory

    For your model, that would mean to match them horizontally; in newer iMacs with vertical RAM installation, they should be matched: slot 1 + 3, and slots 2 + 4 (which, oddly enough, will result in the same picture if your check the RAM in system info).

  • Using ios6 on my iPad I can no longer swipe to hide an app in the App Store. Still works on all other ios and devices. Anyone find the same?

    Using ios6 on my iPad I can no longer swipe to hide an app in the App Store. Still works on all other ios and devices. Anyone find the same?

    The feature no longer works in iOS 6 so you must not have updated your other devices yet.

  • Report to find the retainage amount per each supplier site

    Hi All
    Is there a report to find the retainage amount per each supplier site ?
    Regards;

    Hi.
    The Withholding Tax by Supplier Report shows both supplier and site.
    Octavio

  • I have 8 charges on my debit card within a matter of 30 minutes for the same amount.  Contacted my bank but i need a letter from itunes.  How can i get this for the bank to reverse charges since it's debit card?

    I have 8 charges on my debit card within a matter of 30 minutes for the same amount.   I notified my bank but the bank is asking for itunes to send them a fax.  How can i get this?

    If possible, I suggest changing to a credit card.
    1) There is a max $50 in stolen dollars.
    2) It is easy to dispute a charge.  You call the credit card company. Complain.  They call the retailer & refund you the money. 
    Robert

  • I purchased a new laptop.  I'm trying to find the same version of Acrobat Pro 9.5 I have on my old laptop to install on my new computer.  Any help?

    I purchased a new laptop.  I'm trying to find the same version of Acrobat Pro 9.5 I have on my old laptop to install on my new computer.  Any help?

    I'm using an iMac with the newest OS X Yosemite. I tried to reinstall Creative Cloud, removed all the programs. But I still get the 'old' 2014 version with the Lionhead, not the Sunglasses (october 2014) with interactive libraries. I use Adobe iPad apps, for instance Adobe Brush, Adobe Shape and Adobe Color and it's so great to have all the things you make with these apps in your Illustrator & Photoshop libraries. Somehow it worked om my laptop, but not om my home computer.

  • Complicated Question (see pdf): Use data from one table to find the same data in a second table and take other data from that table and place it in a third table. :)

    I don't even know if this is posible.
    I'm using iwork '09 
    View PDF

    I hope I can clarify:
    For our purposes here:
    Table 1 = "Step 2 - Product Sizes"
    Table 2 = "Option id Master"
    Table 3 = "Export - Product Info"
    Table 1:
    The user would enter values for "productcode," "Horz," and "Vert"
    "Size" would auto fill based on values in Horiz and Vert (I have this taken care of already).
    Table 2: This is a completely static table that I want to search against. - Data from other tables in the doc does not alter or change the data in this doc.
    We just want to look at table 2. Find the existing value in "table 2 : size" column that matches the "table 1 : size" column  and then pull the "optionids" and "productprice" from that row.
    Can the value from "Table 1 : Size" be used as a search term in "Table 2 : Size?"
    Table 3: The user does not enter any values on this table. 
    "productcode" is pulled from table 1 - "Table 1 :: A5" = "Table 3 :: A5"
    "optionids" and "productprice" are pulled from Table 2 columns "D" and "E" - however we do not know which Table 2 row it is pulling from until we enter data in Table 1.
    As I'm writing this I'm realizing that
    A. this is probably really confusing to you.
    B. this may be impossible inside of numbers.
    If you have some other method that would facilitate the same out come but be structured differently please let me know.
    --- maybe to help you understand further what I am doing here is my current workflow:
    I record the size of a piece of art.
    Then I manually go to my "Option id Master" and find the same size.
    I then copy the corresponding "optionids" and "productprice" cells. (these options control the prices displayed on my website)
    I got to my "Export - Product Info" table and paste the values in the corresponding cells.
    I was hoping to automate this as it takes a long time when you have hundreds of products.
    Thanks for the help!

  • Our exchange server crashed and we lost all contact and calendar data.  We found an app to get the contacts off of people's phone to import but can't find the same for calendar.  How do I get my calendar info off my phone and in to new exchange server?

    Our exchange server crashed and we lost all contact and calendar data.  We found an app to get the contacts off of people's phone to import but can't find the same for calendar.  How do I get my calendar info off my phone and in to new exchange server?

    You'd have to think through this, but it seems like if you are using Outlook, and the items vanished from the Outlook client as well as the server,that you could re-populate Outlook using iTunes. 

  • No credit card and cant find the same items anywhere e

    I decided to purchase a zen vision M dock and video cable from the official creative site as i cant find the same items anywhere in a high street shop or anywhere online. I was halted by the fact i don't have a credit card tho i do have debit card, does anyone know how i can
    * purchase the above items from creative or
    2* buy the same items else where if so anyone have some links?
    Thanks.

    <IMG height=0 alt="" src="https://secure.creative.com/images/dot-clear.gif" width=0 border=0><IMG height=3 alt="" src="https://secure.creative.com/images/dot-clear.gif" width=0 border=0>We accept Visa, MasterCard, Discover, and American Express credit cards. We also accept Visa and MasterCard debit cards with a Visa or MasterCard logo on front. If you wish to pay by check, call us at -800-998-000 Monday through Friday, 9AM-6PM, Central Time.All orders are calculated and billed in US dollars.
    For buying elswhere....try to put in the item name in popular searchmachine like Google...Yahoo and so on
    Good luck

  • Where can i find the wall amount for 610 1201

    where can i find the wall amount for 610 1201
    This question was solved.
    View Solution.

    c0rnel wrote:
    Can you give me more descriptions on what a 610 1201 is?
    Monitor? TV? What brand?
    Not having very much luck finding the product you're describing but i'm more than happy to assist you with this.
    I would assume since the OP is posting in the Touchsmart forum they are referring to the Touchsmart 610-1201 computer, no idea why you can't find it, the OP gave all the correct information.
    OP you're probably looking for the #VK554AA adapter, but you will still need an additional VESA wall mount.
    Google for "touchsmart wall mount adapter for vesa wall mount" and you'll see the many sources for this part.

  • Trapcode Particular: Keeping the same amount of particles from start to finish?

    I'd like to move some particles along a motion path, but I need them to start and finish with the same amount.  What I'm doing is moving a "comet" along a motion path. The particles making up the comet are custom particles of a logo element that I want to move throughout a specific scene.
    That part is no problem. I'm just having problems creating - say - 50 particles - and keeping that number from start to finish. Right now the comet keeps emitting new particles. Any setting I've tried either removes or adds too many particles or changes the shape of the emitter. Nothing I've tried seems to work.
    Any advice would be much appreciated.
    Thanks,  Ray

    Should be no problem by keyframing the parameters, so it's not clear to me where you are having problems. The simplest way to get an exact number would be to use a Layer Grid emitter - set it to the desired x and y density in the Options, then set the number of particles to match that value (which apparently only can be x multiplied with y), then animate the Particles/sec. property to only give one burst, e.g. by setting the number to a few 100 first and after only 5 frames animating it to zero. During those five frames all particles should have had a chnace to be born. For the actual path simply use the Motion Path option in the Air physics model based on a light. Either that or you will have to balance out the Inherit Velocity from Motion option with Air Resistance so the particles seem to swarm around the emitter. Likewise, you could use a Radial Field to capture and constrain them...
    Mylenium

  • Finding the same value in different columns

    Hello,
    I am trying to figure out how I would go about finding the same value in the same row but in different columns. For example, in the table sometimes the report name is the same as the description. I would like to find all of the rows where this is the case.
    Thanks
    Report name
    Description
    Date
    Time
    Report 1
    Report 1
    dddd
    tttt
    Report 2
    Billing Report
    dddd
    tttt
    Report 3
    Report 3
    dddd
    tttt

    Hi,
    Is this what you want?
    SELECT  *       -- or whatever columns you want
    FROM    table_x
    WHERE   report_name = description
    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

Maybe you are looking for

  • Anyone having repeated problems trying to install update cloud applications?

    I have always seem to have a large proportion of my CC updates fail with "Installation Failed". Not sure if this is bandwidth related even getting the cloud app to update has been very hit and miss. It seems worst when there are new apps/update batch

  • What is the difference btwn Variable Substitution and Dynami Configuration

    Hi Gurus Could you please explain the difference between the Variable Substituion and Dynamic Configuration. whn shall we use them and in what scenarios? thanx in advance

  • HT1711 Sub-titled movies in iTunes

    I viewed the trailer for a movie in iTunes which had sub-titles.  When I downloaded it to my Apple TV there were no sub-titles.

  • Iphone photo upload

    I have uploaded photos from my iphone into iphoto.  I created a folder and i can locate the photos fine in iphoto.  I then, go to my blog and try to upload photos from iphoto (which were uploaded from my phone) and it won't show the photos uploaded f

  • USB Flash drive not showing on DT

    Hi folks, I received a USB flash drive with 2 GB capacity made by Super Talent (www.supertalent.com- look under Aluminum flash drives). Upon plugging it into the G5's USB port (i've tried them all) I get a "Cannot recognize- Initialize/Ignore/Eject"