Jump to content

Double Query


bearruler

Recommended Posts

I'm not exactly sure how to ask this, so I'm going to try to give an example

I have an operation that will be run by cron, so I don't want it to be too heavy
As of now, It loops though everyone

Each time the file is run, the "Employees" gets 100% of the bosses income, divided amoung themselves. The bosses income does not include the bonus he gets from HIS boss.

So

[table]
[tr]
[td]employee[/td]
[td]boss[/td]
[td]income[/td]
[td]money[/td]
[/tr]
[tr]
[td]10000[/td]
[td]0[/td]
[td]100000[/td]
[td]0[/td]
[/tr]
[tr]
[td]10001[/td]
[td]10000[/td]
[td]50000[/td]
[td]0[/td]
[/tr]
[tr]
[td]10002[/td]
[td]10001[/td]
[td]10000[/td]
[td]0[/td]
[/tr]
[tr]
[td]10003[/td]
[td]10001[/td]
[td]5000[/td]
[td]0[/td]
[/tr]
[/table]


0 means they have no boss
And of course, this would never happen in a real world senario.

Without the boss bonus, it is a simple
[code]$sql="Update `table` SET `money`=`money`+`income`";[/code]
However, I need to give the people with bosses x% of their bosses income

Employee 10000 gets his striaght income because he has no boss
Employee 10001 gets his income (50,000) PLUS his boss bonus. Since 10001 is the only one whos boss is 10000, he gets 100% (100,000). So he gets a total of 150,000
Employee 10002 gets his income (10,000) Plus his boss bonus. This time, there are two people who split it. He gets 50,000 / 2 = 25,000. His total is 35,000
Employee 10003 is the same as above, except he gets only 5,000 plus his 25,000 bonus.

I'm not really sure if this is possible, as it becomes multiple queries within a query....
Thanks,


Bear
Link to comment
https://forums.phpfreaks.com/topic/19155-double-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.