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

  • Home
  • SEARCH
  • 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 9073621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:27:31+00:00 2026-06-16T18:27:31+00:00

I am using sybase. I have a table with columns named time and quantity.

  • 0

I am using sybase.

I have a table with columns named time and quantity. Quantity can be either zero or non-zero. I need to find all the cases where for any time any subsequent quantity within 1 sec is > 0 and original quantity is greater than 40.

I am not able to think this problem in terms of SQL structure but if it were a C++ code I would have easily done it using a for loop, etc.

Let me try to explain this with an example.

From the attached image where I have gathered the data in ascending time:

  • Since quantity at 10.01.01.000 > 40 and 10.01.01.001 > 0 we include 10.01.01.000 in our shorted list

  • We do not include 10.01.01.001 in our shorted list as even though quantity > 0 the next quantity within 1 second i.e. at 10.01.01.002 is 0

  • Row 4 is not included in our sample as there is next even within 1 second

RowNumber   Time        Quantity

1        10:01:01.000     100

2        10:01.01.001     50

3        10:01:01.002      0

4        10:01.01.003    100

5        10:01:03.001    100
  • 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-16T18:27:32+00:00Added an answer on June 16, 2026 at 6:27 pm

    Assuming by “next” you really mean next and there are not multiple records, then you can do this with lead.

    select t.RowNumber, t.Time, t.Quantity
    from (select t.*,
                 lead(time, 1) over (order by time) as nextTime,
                 lead(quantity, 1) over (order by time) as nextQuantity
          from t
         ) t
    where datediff(ms, t.time. t.nexttime) <= 1000 and
          (t.Quantity > 40 and t.nextQuantity > 0)
    

    If you do not have the lead() function, you can do this as follows:

    select t.RowNumber, t.Time, t.Quantity
    from (select t.*,
                 (select min(time) from t t2 where t2.time > t.time) as nexttime
          from t
         ) left outer join
         t tnext
         on tnext.time = t.nexttime
    where datediff(ms, t.time. tnext.time) <= 1000 and
          (t.Quantity > 40 and tnext.Quantity > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 500 stored procedures in a Sybase database. Using SQL, can I get
I have run a query using Eclipse from a Sybase db. I need to
I have a datetime field in a Sybase table, and need to use it
I am using an older version of sybase which does not have keywords like
I have a table with the following columns and data: activity_dt | activity_amt 2009-01-01
In my Sybase 12.0 ASE database, I have at table that contains a column
I have an issue trying to perform bulk load using named pipe on SybaseIQ
I need to insert values in database using Perl's DBI module. I have parsed
I have an ASP SqlDataSource connected to Sybase DB query, using Select Parameters that
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help

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.