Division ( / ) not giving my answer in postgresql

前端 未结 4 1726
梦谈多话
梦谈多话 2020-12-24 04:36

I have a table software and columns in it as dev_cost, sell_cost. If dev_cost is 16000 and sell_cost is 7500

4条回答
  •  余生分开走
    2020-12-24 05:05

    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
    

提交回复
热议问题