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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:56:30+00:00 2026-05-21T10:56:30+00:00

I want to compute scores for some data I have in a MySQL database.

  • 0

I want to compute scores for some data I have in a MySQL database. The score will be computed as follows:

score = COUNT(purchases MADE BETWEEN NOW() AND (NOW() - 1 WEEK))
  + 0.7 * COUNT(purchases MADE BETWEEN (NOW() - 1 WEEK) AND (NOW() - 2 WEEKS))
  + 0.4 * COUNT(purchases OLDER THAN (NOW() - 2 WEEKS))

I have purchses in a table with a purchase_time column.

Is it possible to do this in MySQL and get output similar to the following?

ORDER_ID    SCORE
   3          8
   4          3
   5          15

Thanks

— EDIT —
The table structure is:

tblOrder - table
id - primary key
created - time stamp
  • 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-21T10:56:30+00:00Added an answer on May 21, 2026 at 10:56 am

    Your between and older need to be converted into CASE.

    CASE case_value
        WHEN when_value THEN statement_list
        [WHEN when_value THEN statement_list] ...
        [ELSE statement_list]
    END CASE
    

    At the same time you can rewrite the expression so that specific cases are the factors such as

    SELECT SUM(
             CASE DATEDIFF(now(),purchase_datetime) DIV 7
               WHEN 0 THEN 1
               WHEN 1 THEN 0.7
               ELSE 0.4
             END
           )
    FROM table
    WHERE purchase_datetime < now()
    GROUP BY ORDER_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a database for soccer scores. Obviously, we have: Countries (Netherlands,
I want to ask how to add a computed column in BIRT that compute
May be it sound dumb but if I want some computed value from other
I want to index a computed column in my database table which uses a
I have a list of users: users = [1,2,3,4,5] I want to compute a
I have to make some changes in a small system that stores data in
I have a matrix M thats's 16384 x 81 . I want to compute
I have a square bitmap of a circle and I want to compute the
I want to compute the time 4 hours later during the DST transition, either
For use in a rigid body simulation, I want to compute the mass and

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.