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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:40:22+00:00 2026-06-17T19:40:22+00:00

Yesterday I asked a question about CTEs and running total calculations; Calculating information by

  • 0

Yesterday I asked a question about CTEs and running total calculations;

Calculating information by using values from previous line

I came up with a solution, however when I went to apply it to my actual database (over 4.5 million records) it seems to be taking forever. It ran for over 3 hours before I stopped it. I then tried to run it on a subset (CTEtest as (select top 100)) and its been going for an hour and a half. Is this because it still needs to run through the whole thing before selecting the top 100? Or should I assume that if this query is taking 2 hours for 100 records, it will take days for 4.5 million? How can I optimize this?

Is there any way to see how much time is remaining on the query?

  • 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-17T19:40:23+00:00Added an answer on June 17, 2026 at 7:40 pm

    I think you are better off doing the running sum as a correlated subquery. This will allow you to better manage indexes for performance:

    select memberid,
           (select sum(balance - netamt) as runningsum
            from txn_by_month t2
            where t2.memberid = t.memberid and
                  t2.accountid <= t.accountid
           ) as RunningSum
     from txn_by_month t
    

    With this structure, an index on txn_by_month(memberid, accountid, balance, netamt) should be able to satisfy this part of the query, without going back to the original data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question follows on from a question I asked yesterday about why using the
Yesterday I asked about serving byte ranges from PHP. Today my question is -
Yesterday my friend asked me a question about this query: select * from user
Using PHP 5.x and MySQL 5.x So I asked a question yesterday about the
Yesterday I asked a question about parallel matrix multiplication in Java 7 using the
I asked a question yesterday about using MySQL to tally results to a survey.
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked a question about bigints yesterday which was kindly answered. However, I have
I asked a question about different testing frameworks yesterday. This question can be found
I asked a question about making a greatest n per group type query yesterday

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.