Jump to content

floor Sum and group


Justafriend

Recommended Posts

$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);  
 foreach($dbh->query('SELECT PlayerName,  floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) +   floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 +  floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) AS BB,  floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )*3) +   floor(((SUM(ScoreDiffAlt) + SUM(PdiffS)) /500)*2) + floor(SUM(PScoreReg /1500))*3 +  floor(Sum(scoredifreg /1500))*2 + SUM(prereg) + SUM(st) + SUM(hb) + SUM(Sbonus) + SUM(Ballots) AS TB,
   SUM(Ballots) AS PB FROM spplayer Group by PlayerName
') as $row) {  
$total4 = $row['PB']; 
$total5 = $row['BB'];
$total6 = $row['TB'];

Ok from the above code is used to generate a total of  ballots awarded based on the conditions  Now the catch is if i add a group by and echo it  the total doesn't match what is there now and i have figured out why BUT i need a way to get the totals to match,

The flaw is if i use just this part for an example

floor(((SUM(PScoreAlt) + SUM(PscoreS)) /1000 )

​if the totals are 

jane 1100 the floor would be 1

joe 1400 the floor would be 1

sam 1500 the floor would be 1

moe 1300 the floor would be 1

​but the issue is  even though the total is 4

it is giving me a  floor of  5 as the sum of  the four totals is 5300 with a floor of 5

 

​What i am trying to do is figure out a way of getting a correct  total of all the people so it would be 

floor(1100/1000)+floor(1400/1000)+floor(1500/1000)+floor(1300/1000)

 

any help would be greatly appreciated

Link to comment
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.