Can I use LEAD or LAG with Groups?

Can I use LEAD or LAG with Groups?
I want to compare two records of each group.
Is it possible?
Thanks in advance

Xavi wrote:
I have this query:
SELECT a.cod_riesgo_txpk           as num_poliza,
a.cod_suplementor_txpk      as suplemento,
a.movimiento_nmpk           as movimiento,
a.cod_tipo_operacion_txfk   as tipo_operacion,
rc.fecha_vcto_cobertura_txd as fecha_vto,
rc.capital_asegurado_nm     as capital,
rc.prima_total_nm           as prima
FROM REGU_RIESGOS_COBERTURAS rc, REGU_MOVIMIENTOS_POLIZAS a
WHERE rc.cod_cobertura_txpkfk ='005'
AND rc.cod_riesgo_txpkfk = a.cod_riesgo_txpk
AND rc.cod_suplementor_txpkfk = a.cod_suplementor_txpk
AND rc.movimiento_nmpkfk = a.movimiento_nmpk
order by num_poliza, movimiento;
The results:
NUM_POLIZA     SUPLEMENTO     MOVIMIENTO     TIPO_OPERACION     FECHA_VTO     CAPITAL     PRIMA
0640080109141     0640080109141/014     1     02     01/05/2010     15025302,61     3,19
0640180096274     0640180096274/006     1     02     01/05/2006     1652783     1387,8
0640180365194     0640180365194/005     1     02     08/07/2006     150253     294,83
0640180369821     0640180369821/009     1     02     31/12/2006     13460000     28483,08
0640180369821     0640180369821/010     2     02     28/02/2007     13460000     29546,08
0640180384185     0640180384185/010     1     02     30/12/2006     36085241,96     113951,53Can yo see NUM_POLIZA 0640180369821     I have two records, then I want to compare two rows in each grou.What do you mean by compare? What do you want to do?
You can use the PARTITION BY clause if you want the analytic function to work within a specific group.

Similar Messages

  • How can I use lead/lag in this query

    I have written this query which gives me the comparative data based on this week and next week. How can I use Lead/Lag in this query.
       WITH CURRENT_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+')),
           LAST_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK + 1) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'))
         SELECT   CURRENT_WEEK.YEAR,
                  CURRENT_WEEK.SEASON,
                  CURRENT_WEEK.ACC_SERIES,
                  CURRENT_WEEK.WEEK,
                  CURRENT_WEEK.FAILURES,
                  (CURRENT_WEEK.FAILURES - LAST_WEEK.FAILURES) FAILURES_COMPARE
           FROM   LAST_WEEK, CURRENT_WEEK
          WHERE   CURRENT_WEEK.WEEK = LAST_WEEK.WEEK(+)
       ORDER BY   CURRENT_WEEK.WEEK;Output is like this.
                    YEAR         SEASON     MODEL                     WEEK        FAILURES    Failures_COMPARE
    1     2011     SUMMER     VGP-BMS15     49     10     
    2     2011     SUMMER     VGP-BMS15     50     28       18
    3     2011     SUMMER     VGP-BMS15     51     30       2
    4     2011     SUMMER     VGP-BMS15     52     40       10Edited by: BluShadow on 06-Jan-2012 13:26
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You would jettison the entire LAST_WEEK subquery. Then replace your failure calculation with
        current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compareI suppose you might want to think about renaming the sub-query as well ....
    Cheers, APC
    Edited by: APC on Jan 6, 2012 1:41 PM

  • Can't use function in creating record group

    Gurus,
    This question is for developers. Is this true one can't use
    function in creating record group. I am using form5.
    thanks,
    ZW

    I figured out the issue... they changed the way Group Calls are limited.
    Here's a full explaination - and a suggestion for a behavior fix: http://community.skype.com/t5/Windows-desktop-client/Please-Fix-Group-Video-Voice-Calling-Limit-Beha...
    Long story short, you can't do a video calling at all if the group has more than 10 people in it total (including you).
    Also, you can't do voice calling in groups with more than 25 people.
    Text chats are limited to 300 people (or so I've been told by Skype employees). I've been in a chat with over 100 participants though so I know it goes that high at least.

  • How can I use my Apple ID with 2 Apple devices?

    I just got an ipad mini and I registered it with the same Apple ID I use for my iphone 4s. Everything was fine until I downloaded apps to the ipad and noticed that the ones I had on both devices  no longer opened on my iphone. Why is this? How can I use my Apple ID with 2 Apple devices and how can I recover my apps on my iphone?

    I've had an iPad for almost two years. When I purchased an iPhone last fall I set it up to use the same Apple ID as my iPhone. I've had no problems doing this. Try resetting each device and see what happens.
    First thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider should one appear until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.

  • How can i use my apple ID with the itune store over my windows laptop

    how can i use my apple ID with the itune store over my windows laptop

    If you don't have iTunes installed on your laptop then you can download and install it from here : http://www.apple.com/itunes/download/
    You can then log into your account on it via the Store > Sign In menu option (on iTunes 11 on a PC you can get the menus to show via control-B) :
    And you can then select the Store on the left-hand sidebar (you can enable the sidebar via control-S), and then browse items in the store and buy them by clickin on their price.

  • Can I use an USB disc with my macbook pro bought in 2005.  What capacity will it take 2.00 or 3.00?

    can I use an USB disc with my macbook pro bought in 2005.  What capacity will it take 2.00 or 3.00?

    The first MacBook Pro's were not released until the beginning of 2006, and they had USB 2 ports.
    Anything available new in 2005 would have been a PowerBook G4 and they also had USB 2 ports.
    A USB 3 disk will just transfer data slower then it could do, if you plug it into a USB 2 port though, so you can buy either.

  • I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    do I need to create another account with a different email account
    Yes, the email addresses need to be unique to each device. You may use the same Apple ID on each device, but the email address used by each device needs to be different.

  • How can I use my time capsule with windows7

    How can I use my time capsule with windows7?

    This is asked regularly.
    https://discussions.apple.com/message/10978060#10978060
    Look at the more like this. On the right column next to the post.
    Load airport utility for windows.. which will also load bonjour for windows.
    In windows explorer type \\TCname or \\TCipaddress (replacing with the actual values.. names with spaces will give you trouble so change all names in the TC to SMB compatible or actual ip address).

  • New to Apple products (finally) - can I use my Itunes account with multiple products e.g. Iphone and Ipad?

    New to Apple products (finally) - can I use my Itunes account with multiple products e.g. Iphone and Ipad?

    Oh yes! Apple will be happy for you to buy as many Apple products as you can afford.
    As and when needed, each can be given its own selections of content to sync with.
    tt2

  • Can i use two apple tvs with one itunes account?

    can i use two apple tvs with one itunes account?

    yes and you can use more then 2
    just don't give them the same name

  • Can you use 2 Thunderbolt Displays with Windows 7/Bootcamp on a Early 2011 Macbook pro?

    Can you use 2 Thunderbolt Displays with Windows 7/Bootcamp on a Early 2011 Macbook pro?
    I have 2 and cannot seem to get them to work?

    Can you use 2 Thunderbolt Displays with Windows 7/Bootcamp on a Early 2011 Macbook pro?
    I have 2 and cannot seem to get them to work?

  • I was trying to get the iOS 8.2 on my iPhone 5 but then it stopped and my phone is now on recovery mode I have pictures I need and they did not all fit on iCloud  how can I use the phone again with ALL my pictures and videos without restoring it?

    I was trying to get the iOS 8.2 on my iPhone 5 but then it stopped and my phone is now on recovery mode I have pictures I need and they did not all fit on iCloud  how can I use the phone again with ALL my pictures and videos without restoring it?

    Contacts are designed to be synced to a supported application on the computer or a cloud service.
    Pictures taken with the device are designed to regularly be copied off the device to a computer as would be done with any digital camera.
    If you have failed to use the device as designed it may be too late to recovery anything.
    Is the device regularly backed up to a computer via iTunes?  If so, the most recent backup (when restored to a replacement iOS device) should contain all contacts and pictures as of when the backup was created.

  • Can I use two different devices with different apple ID for backing up data on one machine without losing any data that was backed up with one device earlier?

    Can I use two different devices with different apple ID for backing up data on one machine without losing any data that was backed up with one device earlier?

    The link is to a discussion started on 12/18 in the FiOS Internet forum.  Here's the link I get now, however it is different than the link I pulled a few hours ago.  If this system changes the link again, it may not work.
    http://forums.verizon.com/t5/FiOS-Internet/Frustration-and-just-confused-with-internet-help-please/t...
    You can also look for the topic, "frustration and just confused" in the FiOS Internet forum.
    Here's a link that is in the thread that gives more detail.
    https://secure.dslreports.com/faq/15984
    Good Luck!
    P.S.  "Copper Contributor" is my "rank."  gs0b is my user name.
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer as Accepted Solution so others can see the solution to the problem.

  • HT1206 Can I use one iPod Touch with 2 accounts and download from both accounts?

    Can I use one iPod Touch with 2 accounts? Can I download onto the one iPod from each account?

    I havent seen anything confirming this but I suspect not. that would require you keep logging in and out of the two accounts since you can only sign in to one at once. In iTunes on your computer if you log into another iTunes account you can't log into another one for 90 days. As I say I've seen nothing confirming this on a mobile device, but I suspect it will be the same.

  • Can i use same apple id with 2 iphones

    can i use same apple id with 2 iphones

    Welcome to Apple Support Communities
    Of course. Furthermore, you should do this if both phones are yours, so all your content will get synced and you can use all your purchases in both iPhones

Maybe you are looking for

  • How to set value to Model Node of cardinality 0..N

    hi I am looking for a way to set value to a model node of cardinality 0..N i imported a WSDL into my applicaion , which has the following Node Structure. Context --- ModelNode_Request       ---ModelNode2_Input       ---ModleNode3_Roles  [ cardinality

  • I can´t restore my iPhone, error 3014

    My iPhone appears to have an error named 3014. I can´t get to restore it..

  • Issue with employe attributes in SRM

    Hello All, In ECC HR Organization structure, multiple employees are assigned to single position. The organization structure along with employee data is replicated from ECC to SRM as it is with the help of ALE Standard interface and PFAL execution. Is

  • Do I have you "code" Stumped?

    Hello, First off this riddle is possible, I used to have the code, but I lost the file and the contained code. Riddle: Ok Simply: How do you code inside a table to have it open and display another .html file in it. Complex: Layers are awesome but the

  • Security prompt from Java with missing checkbox

    Hello, In our application we use jnlp link to launch java windows. When we click on the link, appear a sécurity prompt containing, the application name, the editor and 2 location for jnlp (The server adress and on a second line the text "Launched fro