Count between

Hi,
I'm primarily a Java developer, but I have to write a reporting tool in a proprietary framework (read as inflexible framework). I'm stuck with a legacy database. I have a table containing a log of events belonging to different users:
Username Event time Event type
user1 time1 Start
user1 time2 Notify
user1 time3 Notify
user1 time4 Stop
I have 3 types of events, say start, notify and stop. I have to generate a report containing the number of notify's between each start and stop. Is there a way to do this without having to join the table a few times with itself? I also thought of writing a PL/SQL query (but I cannot use functions, so I'll end up with a huge loop with a horrible amount of if then else blocks)
Thanks in advance!
Peter

or, if there can be more Start and Stop events:
SQL> create table mytable
  2  as
  3  select 'user1' username, sysdate-3 time, 'Start' event_type from dual union all
  4  select 'user1', sysdate - 2, 'Notify' from dual union all
  5  select 'user1', sysdate - 1, 'Notify' from dual union all
  6  select 'user1', sysdate, 'Stop' from dual union all
  7  select 'user2', sysdate - 6, 'Start' from dual union all
  8  select 'user2', sysdate - 5, 'Notify' from dual union all
  9  select 'user2', sysdate - 4, 'Notify' from dual union all
10  select 'user2', sysdate - 3, 'Notify' from dual union all
11  select 'user2', sysdate - 2, 'Stop' from dual union all
12  select 'user2', sysdate - 1, 'Stop' from dual
13  /
Tabel is aangemaakt.
SQL> select username
  2       , count(case when time between latest_start_time+1/86400 and first_stop_time-1/86400 then 1 end) count_between
  3    from ( select username
  4                , time
  5                , first_value(time) over (partition by username order by decode(event_type,'Start',0,1),time desc) latest_start_time
  6                , first_value(time) over (partition by username order by decode(event_type,'Stop', 0,1),time) first_stop_time
  7             from mytable
  8         )
  9   group by username
10  /
USERN COUNT_BETWEEN
user1             2
user2             3
2 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Count between two dates.

    dear friends
    i want fetch count between two dates.
    my query is like below.
    SELECT (to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) FROM dual
    its given out like -13 but i want in positive mod like 13 only not '-' Sign.

    just use abs() function to your query to get the positive value
    SELECT abs(to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) diff FROM dual

  • Javascript anomoly on day count between two dates

    Using ApEx 4.0, I have found an anomoly in some javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past-date is on or before March 10, 2013, and the current_date is between March 10, 2013, and November 3, 2013, the day count will be 1 day less than the actual count. Between November 3, 2013, and November 4, 2013, the count increments by 2, and then the count will be accurate from this date forward.
    Here are examples:
    Mar 10, 2013 = 69 days from 31-DEC-2012
    Mar 11, 2013 = 69 days from 31-DEC-2012
    Mar 12, 2013 = 70 days from 31-DEC-2012
    Nov. 3 2013 = 306 days from 31-DEC-2012
    Nov. 4 2013 = 308 days from 31-DEC-2012
    March 11 should be 70, and March 12 should be 71. November 3 should be 307, and November 4 corrects the wrong count which began March 11.
    Changing the past_date to March 10, 2013 produces the following:
    10-Mar-2013 = 0 days from 10-Mar-2013
    11-Mar-2013 = 0 days from 10-Mar-2013
    12-Mar-2013 = 1 days from 10-Mar-2013
    But changing the past_date to March 11, 2013, produces correct numbers:
    11-Mar-2013 = 0 days from 11-Mar-2013
    12-Mar-2013 = 1 days from 11-Mar-2013
    13-Mar-2013 = 2 days from 11-Mar-2013
    I would certainly appreciate anyone's help on identifying the cause of this anomoly. Here is the javascript code:
    var w1= ($v("P48_PAST_DATE"));
    w1 = (w1.toString());
    var vmon = (w1.substr(3,3));
    var vyr = (w1.substr(7));
    var r = (vyr.length);
    if (r == 2)
    vyr = (parseFloat(vyr) + 2000);
    var vday = (w1.substr(0,2));
    var y = (vmon.concat(" ",vday,", ",vyr));
    y = Date.parse(y);
    var w2 = ($v("P48_CURRENT_DATE"));
    var vmon2 = (w2.substr(3,3));
    var vyr2 = (w2.substr(7));
    var vday2 = (w2.substr(0,2));
    var x = (vmon2.concat(" ",vday2,", ",vyr2));
    x = Date.parse(x);
    var numdays = (x - y);
    numdays = (Math.floor(numdays / 86400000));
    $s("P48_NUMBEROFDAYS",numdays);

    Did you google for something like "javascript number of days between two dates". I think you will find the explanation in this observation:
    This method doesn't work properly if there's a daylight savings jump between the two dates.
    There are examples to be found to calculate the difference between two dates.

  • Count between (1 table)

    I want ONLY the IDs which:
    * have "LAP" Between 0901-1033
    * have "UNIT" count as 1
    Table 1
    ID     UNIT     LAP
    1     POL     0902
    1     OOP     1006
    2     LOP     1033
    3     SIN     1101
    4     OOP     0905
    4     OOP     1001
    5     LIP     8001So:
    ID 1 = No because UNIT count is 2
    ID 2 = YES
    ID 3 = NO "LAP" out of range (not between 0901-1033)
    ID 4 = NO Even though its same unit, its been repeated. Only want once.
    ID 5 = NO "LAP" out of range (not between 0901-1033)
    Thanks for help.
    Edited by: Chloe_19 on 29/04/2012 21:42

    Another way could be :
         with count_check as
         (select count(id) ct,id from tablename group by id)
         select a.* from tablename a,count_check b where a.id=b.id and b.ct <2 and a.lap between 0901 and 1033;
    @Kiran, Good way of using 1>= . I have never seen this thing before :). Thanks

  • Switch digital counter to receive counts between samples not between edges

    I'm working with PCI 6602 card. I have created 3 channels:
    Ctr2 works in CI Cnt Edges mode (with Sample clock) and gets the samples.
    Ctr3 works as a pulse generator.
    Ctr4 works as a digital edge which ticks a timed loop where samples from Ctr2 are read (using Counter 1D U32 NSamp mode).
    The problem is that the samples are gathered incrementaly and I want them to be gathered differentialy. Now to know how many samples were gathered during one generated pulse I have to copy the subset of the array with gathered samples and subtract it from original which takes time. Is there any way to avoid it?
    Attachments:
    akwizycja_1FP_5us_histogram_v2_1d.GIF ‏20 KB

    If I understand your question correctly, you can let the counter hardware do this for you by performing Period measurement using Units=Ticks.   Each edge of the sample clock signal will store the count value then reset that count back to 0. 
    To configure this under DAQmx is a little quirky though.  Under edge-counting, you've wired your "channel" signal to the counter's default Source pin and you use your other counter to generate a sample clock signal.  Under period measurement, DAQmx tends to assume that the "channel" signal will be wired to the default Gate pin and act as an implicit sample clock.  It also expects a constant clock signal to be routed to the Source.  You'll have to override these defaults.
    You can use a DAQmx Channel property node to specify that Ctr3InternalOutput should act as CounterInput-->Period-->InputTerminal (or something like that) and that your external signal PFIx should act as Counter-->Timebase-->Terminal.   (Sorry, I don't have LV handy so syntax is very approximate.  Hope it helps you get started at finding the right properties.)   This will let you count differentially, collecting # edges of your channel signal between successive edges of your 200 kHz sampling clock.
    200 kHz continuous sampling for counter measurement is a bit on the aggressive side, by the way.  Not only will it be a bit tricky to keep samples moving across the PCI bus, but you'll probably have fairly significant quantization error at that rate.  If your channel signal is nominally, say, 2 MHz, you'll expect 10 counts per interval.  But the effects of quantization may well give you occasional 9's or 11's for a +/- 10% error per measurement.
    What kind of external "channel" signal are you trying to characterize?  What's the reason for the high sampling rate of 200 kHz?
    -Kevin P.

  • Syncing play counts between two computers

    Is it possible to sync play counts (and other settings such as favorites, playlists, backups, etc) between two computers?
    I purchased a new computer for school, but I am interested in continuing to use my old one as well.  The old one is where my info is accumulated of course, but I would like to add my counts, playlists, ratings etc. from my old computer onto the new one, and hopefully sync them between each other as well.
    As unnecessary as this sounds, I am wondering if it is possible and how it can be achieved.  Any help and/or suggestions would be appreciated.
    Thank you

    iOS devices sync to one computer.
    It is not possible (at least not easily) to sync to multiple computers.
    What you can do is copy the ENTIRE iTunes folder from the existing computer to the new computer.  Then everything in iTunes on the new computer will be exactly as it was on the old computer.
    There is no syncing, at least not within iTunes.
    Other programs do exists that will allow you to sync specific folders between multiple computers.

  • Different file count between Photo Elements 12 and Lightroom 5.

    To Whom it might concern:
    When I check properties the file count in Photo Elements 12 is different than that of Lightroom 5.
    In one case Photo Elements shows 743 files and 51 folders and lightroom shows 734 files.
    I counted each a every file and found Lightroom to have the correct count and Elements the same count
    but properties shows a count of 743.
    Please answer.
    Albert F Schwartz Jr
    E-mail - [email protected]

    If you think you have found a bug, you should report it to Adobe here: http://feedback.photoshop.com/
    This forum is not the place for bug reports

  • Sync Play count between iPod & iTunes when manually update selected

    Hello,
    I use manual updating on iTunes simply because I have so much music, it wont fit onto my iPod, so I manually select the songs I want on.
    I have been reading and find that doing this stops the iPod and iTunes from updating the Play count and Last played. Doesnt this sound a bit daft?
    People have played suggestions such as creating certain playlists that are automatically synced with the iPod, but my songs are all in playlists.
    Is there any addon or way that you can get the iPod and iTunes to automatically sync that part so it updates? Without turning on automatic syncing?
    Thanks

    Playcounts only sync if you are syncing. They don't if you're manually managing your music. Sorry.

  • Different row counts between SQL management studio and Visual Studio

    Hi
    I'm pulling data from a NAV database using a stored procedure containing a Pivot (due to bad table design), the problem is my SQL management studio is returning 53 rows of records yet Visual studio is only returning 5.
    I initially copied the query from management studio into VS to create my dataset, however after returning very few records I used a stored procedure instead.
    Unfortunately the same result occurred, 5 records instead of 53,
    Is there something different between the two systems, perhaps VS doesn't like something in the Pivot?
    Can anyone help?
    Thanks
    Charlie
    CREATE
    PROCEDURE [dbo].[PosReleaseTestPrepared]
    --@Date AS DATETIME
    AS
    BEGIN
    -- -- SET NOCOUNT ON added to prevent extra result sets from
    -- -- interfering with SELECT statements.
    -- SET NOCOUNT ON;
    --    -- Insert statements for procedure here
    DECLARE @cols
    NVARCHAR(MAX),
    @stmt NVARCHAR(MAX)
    SELECT        @cols
    =
    ISNULL(@cols
    +
    +
    + ES.Code
    +
    FROM          
    (SELECT       
    Code
    FROM            dbo.[Branston
    Live$Enquiry Step]
    WHERE        [Enquiry Code]
    =
    'PREPARED')
    AS ES
    SELECT        @stmt
    =
        SELECT *
        FROM
        (SELECT PR.[Entry No_], PR.[Mobile User Code], PR.[Failure Step Code],PR.[Item No_], PR.[Customer No_] ,[Enquiry Step Code],  Value
         FROM dbo.[Branston Live$Positive Release] PR
          LEFT OUTER JOIN dbo.[Branston Live$Positive Release Step] PRS
           ON PR.[Entry No_] = PRS.[Positive Release Entry No_]
         WHERE PR.[Enquiry Code] = ''PREPARED'') PR
         PIVOT
          MAX(VALUE)
          FOR [Enquiry Step Code] in ('
    + @cols
    +
         ) AS P'
    EXEC
    sp_executesql@stmt
    END
    GO

    Hi Satheesh, Latheesh
    I'm using a shared data source in VS, the server and database are definitely pointed to the right location. As is the Stored procedure/SQL query. The table names "PositiveRelease" are bespoke to us and therefore are easy to recognise.
    Below is one of the 5 records from the VS report:
    Mobile   User Code
    Customer   No 
    Item   No 
    Failure Step Code
    Depot   Date
    PP_GY
    102980
    S10586
    DEPOT_DATE
    17/02/14
    Below is the record from the SQL management studio, you can see it is pulling through matching records.
    Mobile User Code
    Customer No_
    Item No_
    Failure Step Code
    DEPOT_DATE
    PP_GY
    102980
        S10586
    DEPOT_DATE
    17/02/2014

  • Different Image Count between a Project in the Project Panel & Browser

    Howdy,
    While in Aperture, after selecting several Master images from a Project using the Browser I deleted them to the Finder's Trash (Master & associated Versions) and emptied the Trash. The image count in the Browser updates but not in the Project Panel.
    I verified that the images have indeed been deleted and were gone by inspecting the Aperture Package Contents and looking inside the specific .approject
    I have not rebuilt the Library.
    I was wondering if anyone else has had this happen or knows of a solution to update the image count in the Project Panel?
    Many thanks.
    love & peace,
    victor
    G5, 2.5 GHz   Mac OS X (10.4.4)  

    [Appearance Preferences|http://documentation.apple.com/en/aperture/usermanual/index.html#ch apter=27%26section=2%26tasks=true]. Check "Show Number of Versions ... ".

  • How to sync play count between new iPad and Mac?

    I recently get a new iPad, and I listen to music on it a lot.  I would like to sync the "recently played" and "play count" with my computer, as I can with my iPhone, but it doesn´t seem to be doing that.  I have the ipad fully updated, and my computer too!
    Any ideas how to do this?
    On another note, my iTunes is allways above the other windows, I have checked my preferences and asked to NOT do this, but it persists.  Any ideas here?

    Forgot to mention, I am NOT using itunes match

  • Find record count between two time stamps

    Hi All,
    Problem: My custom table having a datetime column ;
    I want to find records processed between two time stamps.
    say: records between 2010-04-28 10:15:00 and 2010-04-28 12:30:00
    Could you please help me in this.
    Thanks in advance
    Karri

    use To_date function in where column on that Dat_col
    WHERE date_col BETWEEN TO_DATE ('2010-04-28 10:15:00',
    'mm-dd-rrrr hh24:mi:ss')
    AND TO_DATE ('2010-04-28 12:30:00',
    'mm-dd-rrrr hh24:mi:ss')

  • Missmatch APs count between summary and detail

    Dear All,
    I have a problem on APs count, on WLC (access point summary) I have 83 APs on a/n radio but when I go to detail...there are only 44 a/n radio access point as shown in picture below
    what i must to do to make it match?
    thanks and regards
    Taufan

    That is odd.
    After sometime it is still showing same mismatch?
    Rating useful replies is more useful than saying "Thank you"

  • DAX - Unique count between RELATED tables

    Hi all,
    Having a little trouble with the RELATEDTABLE function.  I'm trying to get a distinct count of a specific value from one table into another table.  I want to get the total count of "Red" from the 'Color' table into the 'Master' table
    for each unique ID.
    The 'Color' table is this:
    ID
    Color
    1
    Red
    2
    Green
    3
    Red
    1
    Green
    2
    Red
    3
    Red
    1
    Red
    The 'Master' table should look like this in the end:
    ID
    Name
    Red
    1
    John
    2
    2
    Mark
    1
    3
    Jason
    2
    Any thoughts?  Thanks.
    UG1

    Sounds like this
    =COUNTROWS(FILTER(RELATEDTABLE(TabB),TabB[Color]="RED"))
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Merge play counts between work and home?

    Hi all,
    I use iTunes at work with a moderately substantial library, mostly made up of songs I haven't listened to much at home which I can stick on an SD card and take in. I also use it here but with a library that is about 4x as big.
    Basically I'm wondering if I can constructively merge or sync the two playcounts? I want to be able to export a list of what happened at work - probably the library in text format - and fold that in to my home iTunes, without destroying my bigger playcounts but just adding to them as if I was using an iPod. Is this possible?
    If it's not, is there a 3rd party tool, script, or plugin that I can use to compare two libraries and merge playcounts constructively (adding two two together?) NB no mac so no applescript.
    Thanks in advance - I've been scratching my head for weeks trying to work this one out.
    -forwar direktion:

    There are programs such as Sync-O-Tunes that can be used to keep two libraries in sync, but I do not think that they merge playcounts.
    As you seem to be aware, the thing you want to do would most naturally be accomplished by using your iPod at work. Assuming you will manage your library at home, and be in "listen only" mode at work, that would be easiest. If you need to, equip your office with a set of desktop speakers having an iPod connection.

Maybe you are looking for

  • Error 65016 when trying to open Dreamweaver

    When I try to open Dreamweaver, I get an error message that just says "65016" and the program crashes. I tried to reinstall using my original installation DVD's, but apparently the install application is no longer compatible with my current version o

  • Group Tree: Error in Ajax response - message: missing } in XML expression

    Hi, We were using a previous version of Crystal libs and viewer. I wanted to get up to date with the latest jars and viewer so I downloaded and installed the version with Eclipse 3.4.1 and crystal development bundled together. I've copied the new jar

  • Oracle Essbase not starting up

    Hi, We are having issues with oracle essbase server in our oracle Hyperion planning system. The ./opmncl startall process gives below error. checked OPMN log and it says, JVM initialization and singleserver signon are succesfull. However, i see error

  • TS4045 thunder bolt cable flickers external screen

    I have a thunderbolt/ mini display port cable and when pluged into either my tv or LG external monitor (via HDMI cable), the screen will occasionally go black for 15 seconds then come back?  The cables are not pinched so I think it's the port.  The c

  • Applying OSS note 859111

    Hi, I need to apply this note. The highest support package for this note in  46C is SAPKH46C50 and in the system tht i am working it is SAPKH46C45 so will it create any problem while implementing the note? if den how do i overcome tht?