Search Postgresql Archives

dividing integers not producing decimal fractions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to produce a decimal fraction by dividing integer fields
like this fragment of the query:

...((cntoh0.count + cntoh1.count)/ttl_deptcat.ttlcount) as "Ratio"...

I get this output

  dept_cat  | cnt_oh_0 | cnt_oh_1 | sum_oh_0+1 | ttl_count | Ratio
------------+----------+----------+------------+-----------+-------
 101500     |      116 |       18 |    134 |   238 |     0
 101800     |      409 |       46 |    455 |   467 |     0
 101900     |      197 |        1 |    198|   198 |     1

Why does "Ratio" display as 0, rather than the proper decimal fraction?
All of the *oh* fields are integers and ttl_count is a bigint. I've
tried wrapping all the integer fields with round(<fieldname>, 3) and I
do get the proper number of zeros to the right of the decimal on the
*oh* fields but not on the "Ratio" field. How do I get fractions when
dividing integers? Cast as something? (I suppose this is going to be
obvious, after-the-fact.)

Thanks for any tips,

r



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux