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

  • Home
  • SEARCH
  • 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 8539791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:27:03+00:00 2026-06-11T11:27:03+00:00

A decimal type field needs to be split up into ranges (intervals), calculated differently

  • 0

A decimal type field needs to be split up into ranges (intervals), calculated differently and then summed up.

This problem concerns field values, not rows.
So for a certain field (fieldX) in every row in a table:

FieldX <  0.013           <----remain just FieldX
FieldX >= 0.013 to 0.026  <----be multiplied with 50%.
FieldX >  0.026           <----be omitted.

Editorial comment: The examples below show for values in the closed-closed range [0.013, 0.026] that the expression is:

  • 0.013 + (FieldX - 0.013) * 0.5

Then these ranges (intervals) or parts needs to be summed.

Example cases:

FieldX     Result
-0.12      -0.12
-0.05      -0.05
+0.05      +0.05                                 — mismatch with specification
+0.011     +0.011
+0.014     +0.0135 = (0.013 + (0.014-0.013)*50%)
+0.021     +0.017  = (0.013 + (0.021-0.013)*50%)
+0.026     +0.0195 = (0.013 + (0.026-0.013)*50%)
+0.031     +0.0195 = (0.013 + (0.026-0.013)*50%) — mismatch with specification

I will hand out a Nobel prize to the genius who solves it!

  • 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-11T11:27:04+00:00Added an answer on June 11, 2026 at 11:27 am
    SELECT SUM(CASE
               WHEN FieldX <  0.013 THEN FieldX
               WHEN FieldX <= 0.026 THEN 0.013 + 0.5 * (FieldX - 0.013)
               ELSE                     NULL
               END)
      FROM YourTable
    

    The aggregates ignore NULL, which is tantamount to omitting it. Note that for SUM(), you could use 0.0 in place of NULL, but not for COUNT or AVG. The other way to ignore rows is to filter them out with a WHERE clause, of course:

    SELECT SUM(CASE
               WHEN FieldX <  0.013 THEN FieldX
               WHEN FieldX <= 0.026 THEN 0.013 + 0.5 * (FieldX - 0.013)
               END)
      FROM YourTable
     WHERE FieldX <= 0.026
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Summary of the problem: For some decimal values, when we convert the type from
I want to convert my float field into a decimal field; I want a
I have a field, justsomenum, of type decimal(3,2) in MySQL that seems to always
I've got a table where I used integer on a field which needs decimal
One of the table I'm trying to query has a field with type decimal(38,19)
I'm using decimal type (.net), and I want to see if two numbers are
I am working with a decimal type in my application and have to submit
In my DB, most numeric values are of type DECIMAL(10,6). They are currency columns.
In C#, there is a type called decimal (the System.Decimal structure). I have found
Which data type is apt to represent a decimal number like 10364055.81. If tried

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.