1

i have a procutd with this price: 60.33. When i increase the price to 20% i got like result 72.39 that is correct. but when i am tryng to decrease to 20% i dont have the same price that i had before. i am having 60.37 some one can help me to tell me what i have to do exactly?

This is the script sql i made to that:

round(listprice +(listprice *(20/100)),2)//Increase 20%
round(listprice -(listprice *(20/100)),2)//Decrease 20%
4
  • 1
    This is about arithmetics, not database administration.
    – mustaccio
    Commented Jan 7, 2020 at 13:06
  • i see...But there is no way to resolve that from sql?
    – Gladiador
    Commented Jan 7, 2020 at 13:13
  • @mustaccio I agree, but it's easy.
    – John K. N.
    Commented Jan 7, 2020 at 13:59
  • Sorry, but this is basic math. And a basic way for hucksters to cheat those who slept through math in school.
    – Rick James
    Commented Jan 8, 2020 at 21:03

2 Answers 2

2

You need the reciprocal value of 20%, because you're new value isn't 120% it is the new 100% value.

round(listprice * 1.2,2) -- increase by 20%

The reciprocal for above +20% would be:

round(listprice / 1.2,2) -- decrease by 17.777777% 

Or put basically: If you want to counteract an increase of 20% then you need to reduce by 17.7777777%.

You can verify this on Windows with the calculator. Beware of the round() function!


Mathematics Explanation

Multiplying a value with a number is another way of adding. If you want to add 100% to a given value, then you can multiply the value with 2:

listprice * 2 

If we replace listprice with 100 then we have:

100 * 2 = 200

This is an increase of 100% compared to the starting value of 100.

If you want to increase a value by 20% then you want to add a fifth of the base value. This is the equivalent of multiplying by 1.2:

100 * 1.2 = 120

Now multiplying by 1.2 can counteracted by dividing the result by 1.2 again:

120 / 1.2 = 100

This is the equivalent of what you are looking for. You want to counteract the addition of listprice +(listprice *(20/100)).


Working Example

A working example can be found at db<>fiddle (MySQL 8.0)


Using the Original Addition

After poring over your equation last night and this morning I found a way of using your original "addition".

                20   
x = y + ( y * ----- )
               100   

This can be converted to:

                20   
x = y * ( 1 + ----- )
               100   

Which as you may note is a multiplication again. So if you were to want the original value of y, then all you need to do is to divide by original multiplicand:

                20   
y = x / ( 1 + ----- )
               100   

Or written as :

          x
     ------------
y =         20        
     (1 + ----- )  
           100

In your MySQL equation this would be:

listprice = round(listprice / (1 + (20/100)),2)

Working Example Using Addition

A working example can be found at db<>fiddle (MySQL 8.0)

4
  • @Jonh aka hot2use, thanks to reply, but there is something that i did not understand what is the "1.2" because the 20% is 0.2 if i have to make 20/100
    – Gladiador
    Commented Jan 7, 2020 at 14:07
  • I understant what you mean, your idea is great, unfortunatly that did not work. for exemple i got a normal price at the database with 60.33 i increase as you did and that give me 72.40 it is correct, and i tried to decrease but that gave me 50.28..that is too far from the first result value that i have in my database :(
    – Gladiador
    Commented Jan 7, 2020 at 14:29
  • That is probably because you did not commit the change to your table, before you conducted the second simple SELECT. If you are only doing a SELECTthen it will not work. I will provide an example.
    – John K. N.
    Commented Jan 7, 2020 at 14:33
  • ooooh John you are right! i have read your explaination i tried it here that works hahahah thanks. you just saved my day!!
    – Gladiador
    Commented Jan 7, 2020 at 14:35
0
UPDATE TABLE_NAME SET CALUMN_NAME = round(CALUMN_NAME * 0.80,2);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.