0

I have a query data from sum function:

ROUND(((nominal)*12) * ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2)/100,2) AS nominal_persentasi,
ROUND((((nominal)*12) * ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2))*(1.1/100)/100,2) AS tambah_persentasi,
ROUND((((nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2))+((((nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2))*(1.1/100))/100,2) AS total_penyesuaian

And the results are:

nominal_persentasi | tambah_persentasi | total_penyesuaian
12.000               3.000               1.203.000

The results produced should be 15,000 , why did it happen ?

I tried to sum the variable nominal_persentasi + tambah_persentasi but the result is 0.

3
  • the results produced should be 15,000 ... which results? Commented Sep 6, 2016 at 4:11
  • 12.000 + 3.000 = 15.000 right? Commented Sep 6, 2016 at 4:14
  • i mean my result is not 15.000 but 1.203.000 it look like combine first data and second data not sum the value Commented Sep 6, 2016 at 4:16

1 Answer 1

1

You are missing a division by 100 in your total. Hence, instead of adding 12,000 and 3,000 to get 15,000 you were actually adding 12,000,000 and 3,000 to get 12,003,000.

SELECT ROUND(( (nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2)/100,2) AS nominal_persentasi,
       ROUND((((nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2))*(1.1/100)/100,2) AS tambah_persentasi,
       ROUND((((nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2)/100) + ((((nominal)*12) *  ROUND((SUM((a.NCI)/3*(60/100))+SUM((b.NSI)/3*(40/100)))/3,2))*(1.1/100))/100, 2) AS total_penyesuaian
FROM yourTable                      -- your query was missing this division by 100           ^^^
Sign up to request clarification or add additional context in comments.

3 Comments

okay...so what i must do? should i use decimal or i must fix the query?I have tried to use decimal in that query but the result is 0
I just fixed your query, cut and paste what I gave above. Or, better yet, just cut and paste verbatim the expressions for the two columns in the sum. You removed a division by 100 which appeared in the nominal_persentasi column.
Nice catch Tim. #EagleEye

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.