The decimal value needs to round up to the nearest integer, it doesn't matter if the fractional part is greater or less than .5.

Here is my query:

SELECT MONTH_ , COST , DISC_COST / COST AS 'amount' , DISC_COST , PROFIT FROM arr WHERE MONTH_ LIKE 'JANU%' 

These are the result:

MONTH_ COST amount DISC_COST PROFIT January 200 1 200 70 January 3500 2,414285714 8450 7250 January 4500 1 4500 2900 January 28500 0,631578947 18000 11200 January 600 1 600 100 
5

2 Answers

Use CEIL() function (MySQL/Postgres).
Use CEILING() function (MS SQL).

SELECT MONTH_ , COST , CEIL((DISC_COST / COST)) AS 'amount' , DISC_COST , PROFIT FROM arr WHERE MONTH_ LIKE 'JANU%' 
5

You can use trunc() to make it integer value by just cut off the decimal values.

SELECT MONTH_ , COST , TRUNC(DISC_COST / COST) AS 'amount' , DISC_COST , PROFIT FROM arr WHERE MONTH_ LIKE 'JANU%' 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy