Re: [SQL] calculating percentages
От | Thomas Good |
---|---|
Тема | Re: [SQL] calculating percentages |
Дата | |
Msg-id | Pine.LNX.3.96.990713090122.13446A-100000@admin.nrnet.org обсуждение исходный текст |
Ответ на | Re: [SQL] calculating percentages ("D'Arcy" "J.M." Cain <darcy@druid.net>) |
Список | pgsql-sql |
On Tue, 13 Jul 1999, D'Arcy J.M. Cain wrote: > Thus spake Thomas Good > > > > How does one do this: SELECT (current_value/target) * 100; > > The divison rtns 0, which multiplied by 100, rtns 0. > > Does "SELECT (current_value * 100)/target" work better? Darcy, SELECT (2 * 100)/3; ?column? ---------------- 66 (1 row) This is clean and I don't have to truncate the value in the end. Thanks! BTW, I noticed an idiosnycratic behaviour that I don't really care for when doing floating point calculations: SELECT (2::float8/3::float8) * 100; ?column? ---------------- 66.6666666666667 <----------------- I don't need to round up here. (1 row) EOF So, Larry W comes in handy again: #!/usr/bin/perl $val = (2/3) * 100; print("$val\n"); 66.6666666666666 ------- North Richmond Community Mental Health Center ------- Thomas Good MIS Coordinator Vital Signs: tomg@ { admin | q8 } .nrnet.org Phone: 718-354-5528 Fax: 718-354-5056 /* Member: Computer Professionals For Social Responsibility */
В списке pgsql-sql по дате отправления: