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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:38:36+00:00 2026-06-06T08:38:36+00:00

I am currently developing an application that makes use of an SQL database. In

  • 0

I am currently developing an application that makes use of an SQL database. In this database I maintain a table called session, which has three fields: a session id (int), a date_created (datetimeoffset), and a date_expired (datetimeoffset) field.

I want to group my sessions in clusters of sessions that the minimum date_created and the maximum date_expired of the sessions not to be more than 6 hours. Also, I don’t want my groups to overlap, i.e. If session s1 belongs to group 1, I do not want it to be also in group 2.

Any ideas?

  • 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-06T08:38:38+00:00Added an answer on June 6, 2026 at 8:38 am

    I suggest you create your 4 data groups like 0-6, 6-12, 12-18 and 18-24, so you can do like this:

    FYI: for the sake of simplicity, I did the case on the date column only, you will need to use a datediff between your date_created and date_expired

    FYI2: change the values on the between as it suits you better and in the end the query will return values to 1, 2, 3 and 4, which you should change to “0 to 6”, “6 to 12” and so one..

    with MyCTE as (
        select case 
                when datepart(hh,date ) between 0 and 6 then 1
                when datepart(hh,date ) between 6 and 12 then 2
                when datepart(hh,date ) between 13 and 18 then 3
                else 4
                end
              as myDatebucket 
        , *
        from session
    ) 
    select myDatebucket, count(*)
    from MyCTE
    group by myDatebucket
    order by myDatebucket
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently developing an application for Windows Phone that makes use of the bing maps
we're currently developing an application that makes extensive use of popup windows(*) and have
I am currently developing a ruby application that has a large number of different
I am currently developing a web application that receives data from an on-site database.
I am developing an application that currently has a View Controller (call it ViewControllerX).
I'm currently developing a small business database application for which we plan to go
I am currently develoing a Rails application which makes heavy use of some javascript
I am currently developing an iPad application that has a Pause button. The entire
I'm currently developing an application in .NET 4 which has to interact with a
I'm currently developing an application that will be run on local network in B2B

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.