Find all the lines from the previous column value difference lines

I have an interesting requirement. There is a DATE column and a user in one table and I have to find all the lines for all users for which the previous and the current line has lagged in lets say more than 30 minutes. The rows are already sorted in time.

For example in the following table, we need to ID 4 and 6 for user 1.


Date of the user ID
1 1 today 1 hr. 0 Min. 0 sec.
today 2 1 1 hour 1 min 0 sec
Today 3 1 1 hour 29 min 0 s
* 4-1 today 1 hour 59 min 3s *.
5 1 today 2 hours 10 min 2 sec
* 6 1 today 2 hours 50 min 7 s *.

Published by: user733179 on March 5, 2009 12:00

Hello

To obtain a separate calculation for each value of the usr, start the analytical clause with "BY usr PARTITION":

WITH     got_dif     AS
(
     SELECT     id,     dt,     usr
     ,     (dt - LAG (dt)
                OVER ( PARTITION BY  usr
                          ORDER BY          dt
                        )
          )             -- difference in days
              * 24 * 60  AS minutes_dif
     FROM     table_x
--     WHERE     ...     -- if needed
)
SELECT     id,     dt,     usr
FROM     got_dif
WHERE     minutes_dif     > 30
;

Tags: Database

Similar Questions

  • How to find all the previous adata firefox?

    I made an account of firefox. Then I uninstalled firefox and install a new one. Now, how can I find all my previous data from firefox.

    If you have enabled Firefox Sync, check out How can I add a device to Firefox Sync?

  • find the cumulative sum of the previous columns

    Hello

    How can I get the cumulative sum of a particular column in the preceding lines in the current line.
    e.g. I have a table produced,

    Date | Orders
    __________________
    1 JANUARY 10 | 3
    JANUARY 2, 10. 5
    JANUARY 3, 10. 1

    I want to select the date and orders between the 1st and the 3rd. Something like...
    Select the Date, the orders for products where Date between to_date('1-JAN-10') and to_date('3-JAN-10')

    But I want the output like this...

    Date | Orders
    __________________
    1 JANUARY 10 | 0
    JANUARY 2, 10. 3
    JANUARY 3, 10. 8

    Similarly, when I select it between 2 and 3, I want the output voltage...

    Date | Orders
    _________________
    JANUARY 2, 10. 3
    JANUARY 3, 10. 8

    and so on. In the output, orders here are the cumulative sum of the previous columns.

    Published by: eric clapton, November 8, 2010 20:45

    Hello

    Use the analytical SUM function.
    You want to filter by date after the cumulative SUM is calculated, so calculate the SUM in a subquery, then filter by date no later than:

    WITH     got_cm_orders     AS
    (
         SELECT     dt
         ,     orders
         ,     SUM (orders) OVER (ORDER BY dt) - orders
                   AS cm_orders
         FROM     products
    )
    SELECT     dt
    ,     orders
    WHERE     dt     BETWEEN     DATE '2010-01-02'
              AND     DATE '2010-01-03'
    ;
    
  • query: find all the rows that are not separate

    Hi first of all I am not dba nor have much experience of fancy requests so be gentle

    Im trying to find all the lines that have a non-distincte value in column "C".
    Therefore, if the values in the column 'C' where:
    4
    54
    33
    4
    1
    9
    9

    the query returns 4 and 9

    I made this request:

    Select t.c
    table t
    where 1 <)
    Select count (c)
    table
    where c = t.c)

    but this looks like n ^ 2 complexity that is too long for the size of this table

    is there a better way?
    Thank you
    select *
      from (select t.*, count ( * ) over (partition by C) cnt
                    from table1 t)
     where cnt > 1
    
  • How is possible to create a smart collection to find all the photos that are not belongs to any collection?

    Hello

    How is possible to create a Smart Collection to find all the photos are not belongs to any collection?

    "Yesterday I was importing a lot of photo when my camera battery died then I succeeded him and continued to import without thinking that the previous import collection literally means" previous import. "

    So I need to find a way to create a smart collection that will reveal all the photos that do not belong to any collection.

    I solved the problem with a workaround is creating a collection based on the date of the photo which worked well, but must be nice to have a more general collection to find all the photo that are not from the collections.

    Thanks in advance,

    Marco.

    Another way to do

    1. Select all photos in the catalog

    2 dismiss a color label

    3. go to collections and multi select all your collections (ctrl)

    4. select images and give them a color

    5. return to the catalogue

    6. filter by color label - No

  • Satellite Pro L40 PSL43E I need to find all the drivers XP

    I need to find all the XP drivers for this laptop in particular. Any ideas where I can find them. on this site, I get only the ' how downgrade "Pease help ASAP.

    If these drivers are available, you will be able to find these drivers on the European driver Toshiba page.

    If the drivers are not available on the European driver Toshiba page, the pilots were not released.

    But I have a suspicion; I found some XP for Sat L40 series drivers. Some series supports the same devices and so the drivers should work also.
    Check some unique XP from different L40 series drivers and maybe he would go.

    Ciao

  • HP Pavilion n072sy-15 Notebook PC - where to find all the drivers for Windows XP and Windows 7

    Who knows where to find all the drivers for Windows XP and Windows 7 for HP Pavilion n072sy-15 Notebook PC?

    Hello:

    XP will not install or run on a PC with an Intel 8 series chipset, so you need not be concerned with finding drivers.

    Here is the link to a template that you can use the W7 x 64 bit drivers from.

    When you install the graphics drivers, first install the Intel HD graphics driver, reboot and then install the graphics driver nVidia.

    DO NOT USE ALL DOWNLOADS OF BIOS OR FIRMWARE FROM THIS LINK

    http://h10025.www1.HP.com/ewfrf/wc/softwareCategory?OS=4063&LC=en&cc=us&DLC=en&sw_lang=&product=6521374

  • remove all links is not finding all the links in my document, it works only on specific links?

    I use acrobat pro 10 and remove it all links work is not finding all the links when the document is clearly all links.

    Test thank you screen name!

    I think that I figured it out, I unchecked create hyperlinks from URLS in the preferences.

  • How can I find all the plugins in the firefox browser

    HI I was wondering if I could ask a question how can I find all the installed plugins in the firefox lasted I would like to be able to know if, for example, if the shockwave plugin is updated and which version is currently installed in the firefox browser lasted.

    Thank you

    Hello Funny78, type Subject: addons in the address bar and then select plugins, add-ons manager opens and you can see the last version of the plugins (and other info), now click on the click to see if your plugins are up to date and see if it is.

    Thank you

  • Where can I find all the drivers Win 7 for Satellite L40 - 14F

    Hi all
    Find all the drivers for L40 laptop model 14F for windows 7 OS? Is that someone has installed this OS? Is it possible to have some problems during installation? Thank you very much.

    Most of the new models is Win8 or Win10 models, they won't get Win7 drivers available.

  • Where can I find all the drivers for Tecra 8200

    Where can I find all the drivers for a Toshiba tecra 8200 PIII750/20/14 t/D/LM/W - I searched for drivers (all drivers) this Labtop can enyone please help me :)

    Got Windows XP:

    Post edited by: Rullings

    Hello

    Have you checked the European driver Toshiba page?
    This site contains all the necessary drivers for Win95, Win98, Win98SE, Win XP, ME, W2k.

    Only Vista drivers are not available for this oldie

    Check it!

  • How to find all the Subvi value changes to a control inside a cluster?

    I have a question I've had brewing for many years now, and as of today, this issue has become less philosophical for me now that I have a VI project with hundreds of screws in there to work through... If I have a cluster which is passed between/through several subVIs, is there a way to find all reads/writes to a particular control within this cluster? For example, if I use a global variable, I can find all the instances where this variable has been changed. Several times, a cluster is used to pass data instead of lots of global variables, but I know not anyway quickly find where specific parts of the latter are read or written in subVIs. Global variables becomes a headache when they are too many of them fly around, but I can't keep track of reads/writes in bunches without manually looking through a few screws hundreds that take in the cluster. Is there a function for this that I'm not aware of? I hope that this question/problem of logic. This may prompt a discussion of architecture, which I would be happy, because I will need to build projects of this scale in the future, but I think also completely stuck when the clusters are used (by me or others) to pass data autour. Thank you! John

    If you ungroup by name and bundle by name, just do a search for text to the name of the control.

  • How to find all the my post anywhere in the forum?

    Desktop HP Pavilion Elite HPE - 110 t... Operating system: Windows 7 Home Premium

    .

    Several months ago (maybe even a couple of years), I discovered that backup/restore are not created.  At this time I posted a question here.  Which lead to a very long series of back & suite assignments between myself & a answering machine (name?) & Finally I planned a daily task to create backup/restore points.  I saved the instructions into a Word document on my computer, but now I can't find them.

    .

    I just found out that there is still no restore point, even though the Task Scheduler shows that he ran this morning @ 02:00.

    .

    I just searched (I thought that all the forums here) for my username (jarhtmd) & only found 4 son, none of whom was what I was looking for.

    .

    How to find all the my post anywhere in the forum?

    Hello:

    Click on your user name to access your user name page.

    Then click recent posts by jarhtmd. Click on view all.

    Maybe it's the post you were talking about.

    http://h30434.www3.HP.com/T5/desktop-operating-systems/scheduling-system-protection-backup-restore-points/m-p/647911#M32431

    Paul

  • How to find all the old files and documents on the hard drive

    Original title: how to find a file

    How to find all THE old files and documents on the hard drive

    Hello

    -Are the old hidden files?

    I recommend you follow the steps in these articles for help.

    Show hidden files
    Find a file or folder

  • I have just re-installed Windows Vista and I can't find all the files he supposedly saved.

    I recently reinstalled vista (yes I know I should have bought mac) in any case I can't find all the files I've supposedly saved. any ideas? Thank you

    original title: Reinstall vista

    Hello

    You don't say how you have reinstalled or how or where or by which program or process, you saved your data...

    A relocation normally will wipe away the old operating system and all data during the resettlement process.

    You can try this free program to see if it can recover your data:

    http://www.Piriform.com/Recuva

    See you soon.

Maybe you are looking for