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 8251217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:09:49+00:00 2026-06-08T00:09:49+00:00

I have table T1 and T2. T1 ID TIME1 TIME2 1001 1 10 1002

  • 0

I have table T1 and T2.

T1

ID    TIME1    TIME2  
1001    1        10
1002    1        20

T2

ID        STATUS    TIME
1001      NEW         1
1001      CLOSED      10
1002      NEW         1
1002      HOLD        5
1002      CLOSED      13

I want result TIME2-TIME1 if status HOLD does not exist in table T2; or TIME2-TIME1-TIME if status HOLD exist in table for that record

1001   9 (10-1)
1002   14(20-1-5)

I initially wrote SQL query but this does not work because it returns NULL for first record while the for the second record result is OK

SELECT T1.ID,T1.TIME2-T1.TIME1-T2.TIME
FROM T1
LEFT OUTER JOIN T2 ON T1.ID=T2.ID AND T2.STATUS='HOLD'

Thanks

  • 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-06-08T00:09:51+00:00Added an answer on June 8, 2026 at 12:09 am

    or in short

    select 
        t1.id,
        t1.time2-case when status='HOLD' then t2.time else 0 end-t1.time1
    from
        t1 left join t2 on t1.id=t2.id and t2.status='HOLD'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of items which change status every few weeks. I want
I have a table that has Time1 and Time2 (for the sake of example).
I have table with date/time column and person column. Each person has multiple records
I have the following table of TIME datatypes clarification: I am representing hours/mins/seconds of
I have a table populated with time stamped rows inserted at (essentially) random point
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have table in which I am inserting rows for employee but next time
Let's say I have the following table: Value Time 0 15/06/2012 8:03:43 PM 1
I have table with a unique auto-incremental primary key. Over time, entries may be
I have a MySQL table where there is a 'date_added' (date) field, 'time_added' (time)

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.