bearruler Posted August 30, 2006 Share Posted August 30, 2006 I'm not exactly sure how to ask this, so I'm going to try to give an exampleI have an operation that will be run by cron, so I don't want it to be too heavyAs of now, It loops though everyoneEach 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 bossAnd 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 incomeEmployee 10000 gets his striaght income because he has no bossEmployee 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,000Employee 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,000Employee 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted August 30, 2006 Share Posted August 30, 2006 There are a number of ways to do this -- you can do it iteratively, but it might be easier to compile all this information in middleware, do the math there, and then run one update statement per employee afterwards. Quote Link to comment Share on other sites More sharing options...
bearruler Posted August 31, 2006 Author Share Posted August 31, 2006 Which would put less load on the server?Bear Quote Link to comment Share on other sites More sharing options...
fenway Posted August 31, 2006 Share Posted August 31, 2006 Well, which server? The DB server has less work to do if you get it all back, do the work, then update as required, but then the bulk of the work is still on the server-side script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.