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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:05:55+00:00 2026-05-11T08:05:55+00:00

The question is how long have these customers been jerks on any given date.

  • 0

The question is how long have these customers been jerks on any given date.

I’m working against Sybase

For this simplified table structure of table history_data

 table: history_of_jerkiness processing_date  name  is_jerk ---------------  ----- ------- 20090101         Matt  true 20090101         Bob   false         20090101         Alex  true         20090101         Carol true         20090102         Matt  true         20090102         Bob   true         20090102         Alex  false         20090102         Carol true         20090103         Matt  true         20090103         Bob   true         20090103         Alex  true         20090103         Carol false          

The report for the 3rd should show that Matt has always been a jerk, Alex has just become a jerk, and Bob has been a jerk for 2 days.

 name    days jerky -----   ---------- Matt    3 Bob     2 Alex    1 

I’d like to find these spans of time dynamically, so if I run the report for the 2nd, I should get different results:

 name    days_jerky -----   ---------- Matt    2 Bob     1 Carol   2 

The key here is trying to find only continuous spans older than a certain date. I’ve found a few leads, but it seems like a problem where there would be very smart tricky solutions.

  • 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. 2026-05-11T08:05:56+00:00Added an answer on May 11, 2026 at 8:05 am

    My solution from SQL Server – same as Dems but I put in a min baseline myself. It assumes there are no gaps – that is there is an entry for each day for each person. If that isn’t true then I’d have to loop.

    DECLARE @run_date datetime DECLARE @min_date datetime  SET @run_date = {d '2009-01-03'}  -- get day before any entries in the table to use as a false baseline date SELECT @min_date = DATEADD(day, -1, MIN(processing_date)) FROM history_of_jerkiness  -- get last not a jerk date for each name that is before or on the run date -- the difference in days between the run date and the last not a jerk date is the number of days as a jerk SELECT [name], DATEDIFF(day, MAX(processing_date), @run_date) FROM (      SELECT processing_date, [name], is_jerk      FROM history_of_jerkiness      UNION ALL      SELECT DISTINCT @min_date, [name], 0      FROM history_of_jerkiness ) as data WHERE is_jerk = 0   AND processing_date <= @run_date GROUP BY [name] HAVING DATEDIFF(day, MAX(processing_date), @run_date) > 0 

    I created the test table with the following:

    CREATE TABLE history_of_jerkiness (processing_date datetime, [name] varchar(20), is_jerk bit)  INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-01'}, 'Matt', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-01'}, 'Bob', 0) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-01'}, 'Alex', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-01'}, 'Carol', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-02'}, 'Matt', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-02'}, 'Bob', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-02'}, 'Alex', 0) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-02'}, 'Carol', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-03'}, 'Matt', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-03'}, 'Bob', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-03'}, 'Alex', 1) INSERT INTO history_of_jerkiness (processing_date, [name], is_jerk) VALUES ({d '2009-01-03'}, 'Carol', 0)  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asking myself this question for a long time now. Thought of
I have not used C++ for a really (really) long time and this question
I have a route defined like this: GET /question/:q_id controllers.Questions.viewQuestion(q_id: Long) Then in my
This is not a question where I don't have any ideas, but instead I
Please forgive my long question. I have an idea for a design that I
Probably a long question for a simple solution, but here goes... I have a
Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:
I have a simple question. I have a long std::string that I want to
Apologies in advance for the long-winded question. I'm really a database programmer, but have
My question (which will follow after this, sorry about the long intro, the question

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.