Division ( / ) not giving my answer in postgresql
Your columns have integer types, and integer division truncates the result towards zero. To get an accurate result, you'll need to cast at least one of the values to float or decimal:
select cast(dev_cost as decimal) / sell_cost from software ;
or just:
select dev_cost::decimal / sell_cost from software ;
You can then round the result up to the nearest integer using the ceil()
function:
select ceil(dev_cost::decimal / sell_cost) from software ;
(See demo on SQLFiddle.)
You can cast integer type to numeric
and use ceil()
function to get the desired output
The PostgreSQL ceil function returns the smallest integer value that is greater than or equal to a number.
SELECT 16000::NUMERIC / 7500 col
,ceil(16000::NUMERIC / 7500)
Result:
col ceil
------------------ ----
2.1333333333333333 3
So your query should be
select ceil(dev_cost::numeric/sell_cost)
from software