divide 10 by 3
Posted in 1994
Topics: General Discussion
This seems more like a procedural problem to me, but I would
very much like a SQL answer to this problem.
I have a cost of $10 that needs to be divided among 3 people.
It is OK for one of them to pay a penny more. I would like
to end up with:
$3.33
$3.33
$3.34
I am willing to build intermediate tables to solve the problem
if it will eliminate the need to use a procedural approach.
I have two tables:
costs
a location_id char(10),
b product number,
cost number(9,2),
number_of_people number
people
a location_id char(10),
person_id char(10),
b product number
the query I have which is not right:
select c.location_id,
p.person_id,
c.cost / c.number_of_people
from costs c,
people p
where p.location_id = c.location_id
and p.product = c.product
;
If you need more info, please email me.
Thanks for any help.
--
Tim Maggio
tim@claremont.com