divide 10 by 3

From: Tim Maggio <tim_at_sun1.claremont.com>
Date: Tue, 1 Mar 1994 14:56:05 GMT
Message-ID: <TIM.94Mar1095605_at_sun1.claremont.com>


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_at_claremont.com
Received on Tue Mar 01 1994 - 15:56:05 CET

Original text of this message