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

The Archive Base Latest Questions

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

CREATE TABLE #TEMPTABLE ( requestTime datetime2, NoOfSessions integer ) INSERT INTO #TEMPTABLE select convert(nvarchar(16),

  • 0

Source Table

CREATE TABLE #TEMPTABLE
(
     requestTime datetime2,
     NoOfSessions integer

)

INSERT INTO #TEMPTABLE
select  convert(nvarchar(16), TimeLog, 120) requestTime , COUNT(DISTINCT SessionId)As NoOfSessions
from  LogData
group by convert(nvarchar(16), TimeLog, 120) order by requestTime;


select  s1.requestTime
,       (
        select  sum(NoOfSessions)
        from    #TEMPTABLE s2
        where   dateadd(minute, -15, s1.requestTime) < s2.requestTime
                and s2.requestTime <= s1.requestTime
        ) as TotalNumberOfSessions
from    #TEMPTABLE s1


DROP TABLE #TEMPTABLE
  • 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-06T09:36:54+00:00Added an answer on June 6, 2026 at 9:36 am

    Try this and let me know. It might be some improvement for you.
    I added a primary key on requestTime in the temp table that can be used in the correlated sub query.

    create table #TEMPTABLE
    (
      requestTime smalldatetime primary key,
      NoOfSessions integer
    )
    
    insert into #TEMPTABLE
    select dateadd(minute, datediff(minute, 0, TimeLog), 0), 
           count(distinct SessionId)
    from  LogData
    group by dateadd(minute, datediff(minute, 0, TimeLog), 0)
    
    
    select  s1.requestTime
    ,       (
            select  sum(NoOfSessions)
            from    #TEMPTABLE s2
            where   dateadd(minute, -15, s1.requestTime) < s2.requestTime
                    and s2.requestTime <= s1.requestTime
            ) as TotalNumberOfSessions
    from    #TEMPTABLE s1
    
    drop table #TEMPTABLE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want script to convert my table CREATE TABLE #TempTable ( Code nvarchar(5) primary
This is query: CREATE TABLE #TempTable(datasize varchar(200)) INSERT #TempTable EXEC sp_spaceused 'Table1' When executing
When I create a temp table using a select into in SQL Server, is
I have the following SQL Server stored procedure : BEGIN TRAN CREATE TABLE #TempTable
I seem to be running into a problem with temp table garbage collection: CREATE
I have the following procedure: CREATE PROCEDURE foo () SELECT * FROM fooBar INTO
Script for table and sample data CREATE TABLE #TEMPTABLE1(ID INT, COL1 NVARCHAR(10)) CREATE TABLE
I have the following Query: create table #Result (Reward varchar(40), Value MONEY); insert #Result
I have temp table #xml that have 2 columns: CREATE TABLE #xml ( id
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL

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.