Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:02:19+00:00 2026-05-16T15:02:19+00:00

I have a table MyTable with columns: ID number (autoincrement) STAT number(3) (status: 1-start,

  • 0

I have a table MyTable with columns:

ID   number       (autoincrement)
STAT number(3)    (status: 1-start, 2-stop)
USER varchar2(15) (user name)
DATE date         (date)

with data:

ID  STAT    USER    DATE
---------------------------------------
1   1   USER1   18.08.2010 13:10:14
2   2   USER1   18.08.2010 15:15:40
3   1   USER1   18.08.2010 16:15:10
4   2   USER1   18.08.2010 18:35:32
5   1   USER2   18.08.2010 07:05:46
6   2   USER2   18.08.2010 13:10:01
7   1   USER1   19.08.2010 09:01:10
8   2   USER1   19.08.2010 16:15:19
9   1   USER2   19.08.2010 11:02:56
10  2   USER2   19.08.2010 18:45:22

How do I get something like this:

USER        DATE       DURATION
--------------------------------
USER1   18.8.2010   04:25:48
USER2   18.8.2010   06:04:15
USER1   19.8.2010   07:14:09
USER2   19.8.2010   07:42:26
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:02:19+00:00Added an answer on May 16, 2026 at 3:02 pm
    create table aa (id number(5), stat number(2), username varchar2(20), d date);
    
    insert into aa
    select 1,   1,   'USER1',   to_date('18.08.2010 13:10:14', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 2,   2,   'USER1',   to_date('18.08.2010 15:15:40', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 3,   1,   'USER1',   to_date('18.08.2010 16:15:10', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 4,   2,   'USER1',   to_date('18.08.2010 18:35:32', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 5,   1,   'USER2',   to_date('18.08.2010 07:05:46', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 6,   2,   'USER2',   to_date('18.08.2010 13:10:01', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 7,   1,   'USER1',   to_date('19.08.2010 09:01:10', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 8,   2,   'USER1',   to_date('19.08.2010 16:15:19', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 9,   1,   'USER2',   to_date('19.08.2010 11:02:56', 'DD.MM.YYYY HH24:MI:SS') from dual union all
    select 10,  2,   'USER2',   to_date('19.08.2010 18:45:22', 'DD.MM.YYYY HH24:MI:SS') from dual 
    
    
    
    
        SELECT username, SomeDATE,
               to_char(to_date('00:00:00', 'HH24:MI:SS') + (duration), 'HH24:MI:SS') TIME
        FROM   (SELECT username, trunc(sd) AS SomeDate, SUM(duration) duration
                 FROM   (SELECT id, Stat, username, d sd,
                                 LEAD(d, 1) over(PARTITION BY username ORDER BY d, stat) - d duration
                          FROM   aa) t
                 WHERE  Stat = 1
                        AND duration IS NOT NULL
                 GROUP  BY username, trunc(sd))
    

    output

    USER1   19.08.2010  07:14:09
    USER2   18.08.2010  06:04:15
    USER2   19.08.2010  07:42:26
    USER1   18.08.2010  04:25:48
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table has a large number of columns. I have a command to copy
I have a table, for example, mytable. It has several columns: col1, col2, col3.
I have a log table that contains job status. One of the columns is
I have a (mysql) database table with the following columns: NAME | String (Unique)
I have a table with many two columns: id, mydate Id is a number;
I have a large table(60 columns, 1.5 million records) of denormalized data in MS
I have a table with columns like this: | Country.Number | CountryName | |
I have three columns in my table - company_name, first_name, last_name . In the
I have two columns in my table and the rows are created dynamically. <table
I have this XML in a column in my table: <keywords> <keyword name=First Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.