dimasadhipradana - 1 year ago 91

MySQL Question

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`

`0`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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 ^^^
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**