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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:46:14+00:00 2026-05-19T14:46:14+00:00

Hi Thanks in advance for helping. I have the following table: create table temp_vol

  • 0

Hi Thanks in advance for helping. I have the following table:

create table temp_vol (symbol nchar(10), dseqkey int, volume float)

here are some values in the table:

symbol     dseqkey    volume (no commas in the actual values)
C          20672      422,764,512 
F          20672       47,144,600 
F          20671       51,695,000 
C          20671      371,950,496 
F          20670       48,680,600 
C          20670      654,208,512 
C          20669      626,121,600 
F          20669       93,489,504 
C          20668      712,674,304 

The output I am seeking is a 2-day simple moving average ((volume dseqkey + volume dseqkey-1) / 2) for each symbol, for each dseqkey. I can get the moving average working for all symbols across one dseqkey. I can get the moving average working for all dseqkeys across 1 symbol. I cannot seem to get both working together.

  • 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-05-19T14:46:14+00:00Added an answer on May 19, 2026 at 2:46 pm

    You could give each row a number using row_number(). That allows you to look up the previous row(s). Example edited for a 3-value moving average:

    ; with numbered as 
            (
            select  ROW_NUMBER() over (partition by symbol order by dseqkey) rn
            ,       *
            from    temp_vol
            )
    select  cur.symbol
    ,       cur.dseqkey
    ,       avg(window.volume) as MovingAverage
    from    numbered cur
    join    numbered window
    on      cur.symbol = window.symbol
            and window.rn between cur.rn - 2 and cur.rn
    group by
            cur.symbol
    ,       cur.dseqkey
    order by
            cur.symbol
    ,       cur.dseqkey
    

    This prints:

    symbol     dseqkey     MovingAverage
    ---------- ----------- ----------------------
    C          20668       712674304
    C          20669       669397952
    C          20670       664334805,333333
    C          20671       550760202,666667
    C          20672       482974506,666667
    F          20669       93489504
    F          20670       71085052
    F          20671       64621701,3333333
    F          20672       49173400
    

    Test data:

    if OBJECT_ID('temp_vol') is not null
        drop table temp_vol
    create table temp_vol (symbol nchar(10), dseqkey int, volume float)
    insert temp_vol values
    ('C', 20672,  422764512 ),
    ('F', 20672,  47144600  ),
    ('F', 20671,  51695000  ),
    ('C', 20671,  371950496 ),
    ('F', 20670,  48680600  ),
    ('C', 20670,  654208512 ),
    ('C', 20669,  626121600 ),
    ('F', 20669,  93489504  ),
    ('C', 20668,  712674304 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks in advance for your assistance. I have the following exported part: [Export (typeof(INewComponent))]
Thanks in advance for helping me out (for those who have time and are
Hello everyone and thanks in advance for reading this.. I have the following html
Thanks in advance for helping, I have a list of one million names and
Sorry if this is too simple, but thanks in advance for helping. This is
Thanks in advance for your help. I have a need within an application to
and thanks in advance for helping. I am creating a log in screen for
Thank you very much in advance for helping! I have this code in bash:
I have the following html: <table> <tr> <td> <input type=button id=btnAdd value=Add /> <input
Thanks in advance to anyone who can think of a more efficient or a

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.