I want to find the difference(duration) between logon and logoff time?

i want to find the difference(duration) between logon and logoff time of below table?
can any one tell the query to find using self join?
USR     LOGON_TIME     LOGOFF_TIME
HR     31-AUG-04 03.04.04.000000 AM     -
HR     - 31-AUG-04 03.04.14.000000 AM
Edited by: 794244 on Nov 1, 2010 10:47 PM

No selfjoin, just analytical functions.
CREATE TABLe log_time
(username varchar(20),
LOGON_TIME timestamp,
LOGOFF_TIME timestamp);
insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate,null);
insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+1/38);
insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate+2,null);
insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+2+14/20);
commit;
SELECT username,logon_time,logoff_time, my_logoff_time, my_logoff_time -logon_time,
       time_to_sort
FROM (
        SELECT username,logon_time, logoff_time,
               LEAD(logoff_time,1,logon_time) OVER (PARTITION BY username ORDER BY time_to_sort) my_logoff_time,
               time_to_sort
        FROM (SELECT username,logon_time,logoff_time,NVL(logon_time,logoff_time) time_to_sort
              FROM log_time)
where LOGON_TIME is not null     
ORDER BY  time_to_sort; 
USERNAME     LOGON_TIME     LOGOFF_TIME     MY_LOGOFF_TIME     MY_LOGOFF_TIME-LOGON_TIME     TIME_TO_SORT
HR     02.11.10 11:34:56.000000000          02.11.10 12:12:50.000000000     0 0:37:54.0     02.11.10 11:34:56.000000000
HR     04.11.10 11:34:56.000000000          05.11.10 04:22:56.000000000     0 16:48:0.0     04.11.10 11:34:56.000000000But, if that code which fills that table should better UPDATE than INSERT. You can cover much more issues. (e.g the DB crashes and you get 2 logon but no logoff in a sequence and.....)
-- andy

Similar Messages

  • Hi, i want  to find the difference in days of two students Date Of Birth

    hi, i want to find the difference in days of two students Date Of Births
    how can i find.
    please help me

    i didn't find what u saidLet me help you:
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=difference+between+dates&subCat=siteforumid%3Ajava54&site=dev&dftab=siteforumid%3Ajava54&chooseCat=javaall&col=developer-forums

  • What is the difference/comparison between AppRf and WebCC ?

    Q: What is the difference/comparison between AppRf and WebCC ?
    A:  
    Comparison between AppRf and WebCC:
    AppRF
    WebCC
    2300+ Apps under 21 app categories
    Millions of URLs under 80+ categories
    Need up to 7 packets to classify
    Classified once HTTP GET is received
    Classification
    Classification + Reputation
    Need AOS upgrade to get new Apps
    Dynamic update of WebCC database
    Static content based classification
    Dynamic content based categorization / reputation

    Or put another way:
    Albums organise Photos
    Folders organise Albums
    A Photo cannot be in a Folder, only in an Album.

  • Want to find the screen exits in VA01 and VA02

    Hi All,
      I want to find the screen exits in VA01 and VA02.
      How to find these screen exits.
      Actually i wnat to add a new custom field to the Additional data B tab on the header of VA01 transaction code.
    Now intially i want to know whether there are screen exits in VA01 transaction code ?If yes please provide the names?
    Please help me regarding this.

    Please check this
    http://help.sap.com/saphelp_46c/helpdata/en/1c/f62c7dd435d1118b3f0060b03ca329/content.htm
    The SAPMV45A , 8309 screen is the Additional Data B tab  to add your custom fields . To capture the data from this custon field you can use
    the user exit MV45AFZZ, USEREXIT_SAVE_DOCUMENT_PREPARE OR
    USEREXIT_SAVE_DOCUMENT depening on your functionality.
    Thanks
    Vinod

  • What is(are) the difference(s) between iphoto and imovie apps for the imac as against ipad3?

    What is (are) the difference(s) between iphoto/imovie apps for the ipad as against imac?

    The Mac version would be more complex and be able to do more stuff, while the iPad version can do more simple things due to the lower processing power and the fact that it's an iPad.

  • HT1178 What the difference is between WPA and WPA2 and how are these settings affecting the access of other computers to the internet through my Time Capsule

    I have a Time Capsule of the 4th generation and I am pretty impressed since I just had a fried harddrive on my 3 month old Imac and Time Capsule restored it fully including all programs etc. without having me to put in all serial numbers etc. for that I give it an A+. However what I find very frustrating is the very short and incomplete user manual and setup instructions. I give those a D-. It does not explain the consequences of certain choices to a normel non computer gig user like me:
    I do not understand what the consequences and difference is between the security setting WPA/WPA2 and WPA2 when setting it up. It would be helpful if the manual would explain something like: If you set it onto WPA2 then computers older than XXX years will not able to hook up to the internet through your router...or the likes, since I slowly supect this may be the reason for some of my troubles.
    I also have a 5 year old PC with vista connected to the Time Capsule. It can wireless connect to the Time Capsule and access the printer (I have managed that after some painful hours...) but it cannot access the internet with that PC through the timecapsule wireless, only if I hook it up with a cable. Why? Does that have to do with the fact that I have set the TIme Capsule to WPA2?
    Our PS3 can connect wireless, no problem. However, I friend of mine tried it with a quite new Toshiba Notebook and he could see the Time Capsule but again it shows the line from the Time Capsule to the internet blocked. All other computers linked with data cable to the Time Capsule are connected to the internet no problem. What have we done wrong? Should I change the security setting to WPA/WPA2?
    I tried the latter, but then another problem does come up, which was there from beginning on: When I change the settings for my Time Capsule my Imac suddenly cannot find the Timne Capsule anymore, even so I am only 3feet away from it. When I set it up for the first time 3 month ago it drove me crazy. The very first time it found the Time Capsule right away. But when I discuverd a mistake in my initial setup and I went through the settings again to change stuff it suddenly could not find the Time Capsule anymore. Only after frustrating 20 times or so with turning wi-fi on and off several times inbetween did it suddenly find the Time Capsule in the set up menu. However, when I tried changing my security setting to WPA/WPA2 today to see whether this solves my other problems again it could not find the Time Capsule when I was finished with the settings and I had to give up/cancel. Why is that???
    I would really appreciate some help here. But please I am not a computer gig and normally always had assistance with these things. On the other hand I am not all stupid either (even so these manuals assuming we all grew up sleeping on a computer make me feel stupid).....
    Thank you all in advance

    Hello Schimi. The Time Capsule is a kind of product that offer you two possibility:
    - To use the TC as a router or as an external HD.
    The difference between WPA and WPA 2 are:
    - They are two kinds of internet connection.
    WPA uses dynamic key encryption , which means that the key is constantly changing and makes the invasion of a wireless network more difficult than WEP . WPA is considered one of the highest levels of wireless security for your network and is recommended if your devices support this kind of encryption . Newer routers offer WPA2 security . WPA2 is compatible with WPA , but offers higher security level . In fact, it meets the high standards of many government agencies . If the router and computer support WPA2 , this should be your choice.
    If you need any help or if you find some difficult setting up it you can contact Apple Support.
    I am sure that they can help you with that.
    I am sory for the delay. I holpe that you solve your issue.

  • What is the difference in between folder and album in iPhoto?  Is a folder a part of an album or vice versa?

    What is the difference in iPhoto between a folder and an album? Are folders part of an album or vice versa?

    Or put another way:
    Albums organise Photos
    Folders organise Albums
    A Photo cannot be in a Folder, only in an Album.

  • To find the field values of Start and End time

    Hi
    The workcenter idoc LOIWCS02 is not populating the fields
    start time BEGZT and endtime ENDZT
    Actually these fields are stored in KAPA table.i can see the field entries thru the transaction CR03 but those values are not stored in KAPA tables.
    when i click intervals and shifts tab in CR03 I can see the start time BEGZT and endtime ENDZT values but when i go to the database table KAPA these field values are empty.
    Does anybody know where to get these values
    Is SAP not storing these values
    Please let me know

    Hi
    Thanks for your reply
    I already tried that ...no data populated..it seems to be an SAP bug...we are using 4.7
    Let me know if you know any futher info on this
    Thanks
    MM

  • Difference(s) between Fieldpoint and RIO?

    Hello,
    I am pretty new to to PACs. I am finding it really hard to find the difference(s) between cFP and RIO. Where should i choose cFP over RIO?
    Some kind of practical comparison here shall be highly appreciated.
    Regards,

    Hi Mirza,
    Your specific application is going to determine which equipment is best. I found a couple of online presentations about CompactRIO and FieldPoint which should provide you with more insight about the functionality of each product:
    CompactRIO Presentation
    FieldPoint Presentation
    Also, here are the links to the product pages for FieldPoint and CompactRIO. I hope that you find this information helpful.
    Regards,
    Hal L.

  • Difference/relationship between XML and XSD

    Hi All,
    Correct me if i am wrong,
    When we create a source and a target datatype in IR automatically objects will be created in XSD.
    The same way it does when we create message type.
    In message mapping, We map source and target message type and when we test with sample data, we can view source and target in xml
    My question is what is the difference/relationship between XML and XSD ?
    Thanks,
    ss

    Hi,
    XML (Extensible Markup Language) is a W3C initiative that allows information and services to be encoded with meaningful structure and semantics that computers and humans can understand. XML is great for information exchange, and can easily be extended to include user-specified and industry-specified tags.
    Whereas
    An XML Schema Definition (XSD) is an instance of an XML schema written in the XML Schema language. An XSD defines a type of XML document in terms of constraints upon what elements and attributes may appear, their relationship to each other, what types of data may be in them, and other things. It can be used with validation software in order to ascertain whether a particular XML document is of that type, and to produce a Post-Schema Validation Infoset.
    I hope this clarifies.
    Regards.
    Praveen

  • Find the difference between two columns in an ssrs matrix ? MSCRM

    Hi All,
    I am working in reporting part of our project (On-line MSCRM 2013) & in reporting services.
    I am trying to create report using fetch xml based. Below is the snap what we required the result.
    Kindly help me, how to get the difference in both column. (Its a matrix table where year is grouped).
    We need difference between both year Like (Plan Revenue of 2013 & Plan Revenue of 2014 difference in Plan Revenue Diff section) and same for Actual
    Revenue.
    https://social.microsoft.com/Forums/en-US/054d5ca4-0d38-4dc6-84a8-88866cc228fe/find-the-difference-between-two-columns-in-an-ssrs-matrix-mscrm?forum=crmdevelopment
    Thanks,
    Mohammad Sharique

    Hi Bro,
    I used parametrized option for year and done the report,Currently we are getting values in Difference column now i want to show
    that value in percentage. How can we show the percentage based on that value. Means i want to show the Difference in Percentage. 
    Kindly help me i tried but getting some issue. Below i am mentioning the code and snap with result.
    Below expression using to showing Plan Revenue in Percentage for year.
    =
    Sum(IIF(Fields!new_year.Value =Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    - Sum(IIF(Fields!new_year.Value =Parameters!EndYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    /IIF(Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))>0,
    (Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0))))
    ,1)
    )*100))
    Result issue is as below in snap with highlighted in red colour.
    Kindly help me on this issue also :)

  • I want to know the difference between iphoto master folder and previews folder

    I want to know the difference between iphoto library master folder and previews folder.. my pictures is stored in master but part of them is also copied into previews.. it occupied too much space.. if I can't change anything in iphoto library, any way to save the space for iphoto? 70G for almost 15,000 pictures, is it reasonable?
    i use mac book pro, ilife 11..

    70GB for 15,000 photos is reasonable, yes, if the photo files are large.
    DO NOT meddle with the contents of your iPhoto Library in any other way than using the commands available in the iPhoto application. What appear to be duplicate files stored in different parts of the library are NOT duplicates, and if you attempt to save space by deleting things in the Finder, you will wreck your library and land in a world of trouble.

  • Finding the difference in no. of days between 2 dates

    Finding the difference in no. of days between 2 dates

    http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A54&qt=days+difference&x=12&y=11

  • Query to find the difference between the last date and the second to the last date

    Hi all,
    Hope all is well.
    I am working on the following problem because I am trying to improve my MS SQL skills. But I am stuck at the moment and I wonder if you could provide some assistance please. Here is the issue:
    Table 1: Dividends
    divId
    ExDate
    RecordDate
    PayDate
    Amount
    Yield
    symId
    1
    2013-02-19
    2013-02-21
    2013-03-14
    0.23
    0.00000
    3930
    2
    2012-11-13
    2012-11-15
    2012-12-13
    0.23
    0.00849
    3930
    3
    2012-08-14
    2012-08-16
    2012-09-13
    0.20
    0.00664
    3930
    4
    2012-05-15
    2012-05-17
    2012-06-14
    0.20
    0.00662
    3930
    5
    2012-02-14
    2012-02-16
    2012-03-08
    0.20
    0.00661
    3930
    6
    2011-11-15
    2011-11-17
    2011-12-08
    0.20
    0.00748
    3930
    7
    2011-08-16
    2011-08-18
    2011-09-08
    0.16
    0.00631
    3930
    8
    2011-05-17
    2011-05-19
    2011-06-09
    0.16
    0.00653
    3930
    9
    2011-02-15
    2011-02-17
    2011-03-10
    0.16
    0.00594
    3930
    10
    2010-11-16
    2010-11-18
    2010-12-09
    0.16
    0.00620
    3930
    11
    2010-08-17
    2010-08-19
    2010-09-09
    0.13
    0.00526
    3930
    12
    2010-05-18
    2010-05-20
    2010-06-10
    0.13
    0.00455
    3930
    13
    2010-02-16
    2010-02-18
    2010-03-11
    0.13
    0.00459
    3930
    Table 2: Tickers
    symId
    Symbol
    Name
    Sector
    Industry
    1
    A
    Agilent Technologies Inc.
    Technology
    Scientific & Technical Instruments
    2
    AA
    Alcoa, Inc.
    Basic Materials
    Aluminum
    3
    AACC
    Asset Acceptance Capital Corp.
    Financial
    Credit Services
    4
    AADR
    WCM/BNY Mellon Focused Growth ADR ETF
    Financial
    Exchange Traded Fund
    5
    AAIT
    iShares MSCI AC Asia Information Tech
    Financial
    Exchange Traded Fund
    6
    AAME
    Atlantic American Corp.
    Financial
    Life Insurance
    7
    AAN
    Aaron's, Inc.
    Services
    Rental & Leasing Services
    8
    AAON
    AAON Inc.
    Industrial Goods
    General Building Materials
    9
    AAP
    Advance Auto Parts Inc.
    Services
    Auto Parts Stores
    10
    AAPL
    Apple Inc.
    Technology
    Personal Computers
    11
    AAT
    American Assets Trust, Inc.
    Financial
    REIT - Office
    12
    AAU
    Almaden Minerals Ltd.
    Basic Materials
    Industrial Metals & Minerals
    I am trying to check the last date (i.e. max date) and also check the penultimate date (i.e. the second to the last date).  And then find the difference between the two (i.e. last date minus penultimate
    date).
    I would like to do that for each of the companies listed in Table 2: Tickers.  I am able to do it for just one company (MSFT) using the queries below:
    SELECT
    [First] = MIN(ExDate),
    [Last] = MAX(ExDate),
    [Diff] = DATEDIFF(DAY, MIN(ExDate), MAX(ExDate))
    FROM (
    SELECT TOP 2 Dividends.ExDate
    FROM Dividends, Tickers
    WHERE Dividends.symId=Tickers.symId
    AND Tickers.Symbol='MSFT'
    ORDER BY ExDate DESC
    ) AS X
    Outputs the following result:
    First
    Last
    Diff
    2012-11-13
    2013-02-19
    98
    But what I would like instead is to be able to output something like this:
    Symbol
    First
    Last
    Diff
    MSFT
    2012-11-13
    2013-02-19
    98
    AAN
    2012-11-13
    2012-12-14
    1
    X
    2012-11-13
    2012-12-14
    1
    Can anyone please let me know what do I need to add on my query in order to achieve the desired output?
    Any help would be greatly appreciated.
    Thanks in advance. 

    Could you try this?
    create table Ticker (SymbolId int identity primary key, Symbol varchar(4))
    insert into Ticker (Symbol) values ('MSFT'), ('ORCL'), ('GOOG')
    create table Dividend (DividendId int identity, SymbolId int constraint FK_Dividend foreign key references Ticker(SymbolId), ExDate datetime, Amount decimal(18,4))
    insert into Dividend (SymbolId, ExDate, Amount) values
    (1, '2012-10-1', 10),
    (1, '2012-10-3', 1),
    (1, '2012-10-7', 7),
    (1, '2012-10-12', 2),
    (1, '2012-10-23', 8),
    (1, '2012-10-30', 5),
    (2, '2012-10-1', 10),
    (2, '2012-10-6', 1),
    (2, '2012-10-29', 7),
    (3, '2012-10-1', 22),
    (3, '2012-10-3', 21),
    (3, '2012-10-7', 3),
    (3, '2012-10-12', 9)
    WITH cte
    AS (SELECT t.Symbol,
    d.ExDate,
    d.Amount,
    ROW_NUMBER()
    OVER (
    partition BY Symbol
    ORDER BY ExDate DESC) AS rownum
    FROM Ticker AS t
    INNER JOIN Dividend AS d
    ON t.SymbolId = d.SymbolId),
    ctedate
    AS (SELECT Symbol,
    [1] AS maxdate,
    [2] AS penultimatedate
    FROM cte
    PIVOT( MIN(ExDate)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery),
    cteamount
    AS (SELECT Symbol,
    [1] AS maxdateamount,
    [2] AS penultimatedateamount
    FROM cte
    PIVOT( MIN(Amount)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery)
    SELECT d.Symbol,
    MIN(MaxDate) AS maxdate,
    MIN(penultimatedate) AS penultimatedate,
    DATEDIFF(d, MIN(penultimatedate), MIN(MaxDate)) AS numberofdays,
    MIN(MaxDateAmount) AS maxdateamount,
    MIN(penultimatedateAmount) AS penultimatedateamount,
    MIN(MaxDateAmount) - MIN(penultimatedateAmount) AS delta
    FROM ctedate AS d
    INNER JOIN cteamount AS a
    ON d.Symbol = a.symbol
    GROUP BY d.Symbol
    ORDER BY d.Symbol
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.
    Thanks!
    Aalam | Blog (http://aalamrangi.wordpress.com)

  • Need to find the Difference between two table

    Hello ,
    I have stucked in program as below scenario:-
    I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
    By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
    Example TableA
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    80 DEF 6005 YY 446 YY8
    TableB
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    81 DEF 6005 Yu 447 YY8
    I need to the out put like this :-
    The Diffence between two table is
    TableA.COL1=80 TableB.Col1=81, Different
    TableA.Col4=YY TableB.col4=Yu,Different
    TableA.Col5=446TableB.col5=447,Different
    Please suggest me to write the pl/sql program for the same
    thanx in advance
    KK

    Thanx friends for all your efforts
    I have a sample code for the same,this will compare the two tables for single row in each table .
    what r the modification needed for the multiple rows of values in the two tables??
    Please suggest!!
    CREATE OR REPLACE PROCEDURE test_compare
    IS
    TYPE t_col
    IS
    TABLE OF VARCHAR2 (30)
    INDEX BY PLS_INTEGER;
    l_col t_col;
    j NUMBER := 0;
    l_sql VARCHAR2 (2000);
    col1 VARCHAR2 (30);
    col2 VARCHAR2 (30);
    val1 NUMBER;
    val2 NUMBER;
    status VARCHAR2 (30);
    CURSOR c1
    IS
    SELECT column_id, column_name
    FROM all_tab_columns
    WHERE table_name = 'TEST1';
    BEGIN
    FOR i IN c1
    LOOP
    j := j + 1;
    l_col (j) := i.column_name;
    END LOOP;
    FOR k IN 1 .. j
    LOOP
    l_sql :=
    'SELECT '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST2.'
    || l_col (k)
    || ', '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST1.'
    || l_col (k )
    || ', '
    || 'DECODE(TEST2.'
    || l_col (k)
    || ' -TEST1.'
    || l_col (k)
    || ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
    EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
    IF status = 'CHANGED'
    THEN
    DBMS_OUTPUT.put_line( 'TEST2.'
    || col1
    || '='
    || val1
    || ', TEST1.'
    || col2
    || '='
    || val2
    || ', '
    || status);
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
    END;
    /

Maybe you are looking for

  • Xml transformation of element attributes ?

    I have already build a succesfull transformation with an xml file I could define myself. now I get an xml file out of another software pacakge that I also try to transform into tables. the structure is totally different since this vendor puts all the

  • Connecting to an Electronic Signature Pad

    Hello, We have just purchased Acrobat 9.0 Pro for our business and are trying to get it to work with an electronic signature pad. Both the ignature pad and Acrobat are installed and working: I was told by multiple different personel that Acrobat woul

  • Did 10.7.1 kill my DVI?

    Hey folks. I use a 2.66ghz dual core i7 mbp, 15", 1680x1050 res screen. I use the minidp to dvi plug to connect to my samsung syncmaster 2333sw I was doing up some rearranging of my desk, and I needed to temporarily unplug the adaptor from my laptop.

  • Displaying in a main report one field's comma separated values in a subreport

    Post Author: shalbert CA Forum: Formula I have two database tables Fields and Memfields: Fields Table ID LABEL 1 A 2 B 3 C 4 D Memfields Table ID LABEL 1 B,D 2 C,A 3 A,D 4 A,B So what I want to do is create a mainreport linking the sub-report by {fie

  • CFTRY

    I'm curious why with this: <cftry> <cfquery name="AddRequest" datasource="SB"> insert into inforeq (Cust_Name, Cust_Address, Cust_Address2, Cust_City, Cust_State, Cust_Zip, Cust_Email, Cust_MailInfo, Cust_Events, Cust_Class, Cust_Info_Sent, Cust_News