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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:32:06+00:00 2026-05-27T21:32:06+00:00

Given a table of user points earned, I need to calculate a six month

  • 0

Given a table of user points earned, I need to calculate a six month half-life of the cumulative points earned. That is, all points earned in the past 6 months are valued at 100%, 6-12 months at 50%, 12-18 months %25, etc.

Here is my best attempt using a CTE:

DECLARE @t AS TABLE (
    ID int NOT NULL, 
    DT SMALLDATETIME NOT NULL, 
    POINTS int NOT NULL, 
    UserId INT NOT null, 
    POINTS_TOTAL INT NOT NULL)
INSERT INTO @t 
VALUES (1, '1/1/2010', 20, 1, 20)
    ,(5, '7/1/2010', 30, 1, 50)
    ,(7, '1/1/2011', 10, 1, 60)
    ,(8, '7/1/2011', 15, 1, 75)
    ,(9, '12/25/2011', 15, 1, 90)

;WITH ctePts AS 
    (SELECT t.*, POINTS AS Decay
    FROM @t AS t
    WHERE t.DT > DATEADD(mm, 6, GETUTCDATE())

    UNION ALL

    SELECT t.ID, t.DT, t.POINTS, t.UserId, t.POINTS_TOTAL, CAST(ctePts.Decay * 0.5 + t.POINTS AS INT) AS Decay
    FROM ctePts
    INNER JOIN @t AS t
        ON t.UserId = ctePts.UserId 
            AND t.DT <= ctePts.DT AND t.DT > DATEADD(mm, 6, ctePts.DT)
)
SELECT *
FROM ctePts

The final table would have a HALF_LIFE column that contains the adjusted sum of all points earned for that user. I should be able to run the following query to get the user’s current point status (total accumulated points those adjusted for half-life decay) for any given point in time:

SELECT UserIdInt, POINTS, POINTS_HALFLIFE FROM 
    (SELECT UserIdInt, 
                ISNULL(p.POINTS_TOTAL,0) AS POINTS, ISNULL(p.POINTS_HALFLIFE,0) POINTS_HALFLIFE,
                ROW_NUMBER() OVER (Partition BY UserIdInt ORDER BY p.ID DESC) AS rownum

    FROM  dbo.USER_POINTS p ) a
WHERE rownum = 1
  • 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-27T21:32:07+00:00Added an answer on May 27, 2026 at 9:32 pm

    Is this what you need?

    SELECT *,
           POINTS / POWER(2E0, ( ( DATEDIFF(MONTH, DT, GETUTCDATE()) - 1 + 
                               CASE
                                 WHEN DAY(DT) <= DAY(GETUTCDATE()) THEN 1
                                 ELSE 0
                               END ) / 6 ))
               AS POINTS_HALFLIFE
    FROM   @t
    

    Returns

    ID          DT                      POINTS      UserId      POINTS_TOTAL POINTS_HALFLIFE
    ----------- ----------------------- ----------- ----------- ------------ ----------------------
    1           2010-01-01 00:00:00     20          1           20           2.5
    5           2010-07-01 00:00:00     30          1           50           7.5
    7           2011-01-01 00:00:00     10          1           60           5
    8           2011-07-01 00:00:00     15          1           75           15
    9           2011-12-25 00:00:00     15          1           90           15
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
For a given table 'foo', I need a query to generate a set of
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
Given a table or a temp table, I'd like to run a procedure that
Given a table where the first column is seconds past a certain reference point
There's a many-to-many UserFeed table that stands between User and Feed and denotes a
Given table: ID ONE TWO X1 15 15 X2 10 - X3 - 20
I am trying to link two fields of a given table to the same
Given a table (mytable) containing a numeric field (mynum), how would one go about
Given a table named person (in a MySQL database/schema), kind of like this one:

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.