所以我有一个数据库需要输出我们每场比赛的投注利润。如果他们在每场比赛中下注1美元,我想输出用户会做出什么,但我也希望显示用户在每场比赛中下注5美元时会做出什么。赔率输入两列OddsNumerator和OddsDenominator。所以,如果赔率为5/6则获胜。 5将在OddsNumerator列中,而在OddsDenominator列中为6。
继承了我的尝试,但这并没有带来正确的利润。
$data40 = mysql_query("SELECT sum(oddsnum / oddsden) FROM stats WHERE MONTH(date) = MONTH(CURRENT_TIMESTAMP) AND winloss = 'Win'");
$info40 = mysql_fetch_array($data40);
$onedollarwins = array_sum($info40);
$data41 = mysql_query("SELECT sum(oddsnum / oddsden) FROM stats WHERE MONTH(date) = MONTH(CURRENT_TIMESTAMP) AND winloss = 'Loss'");
$info41 = mysql_fetch_array($data41);
$onedollarloss = array_sum($info41);
$onedollarprof = $onedollarwins - $onedollarloss;
$onedollarprof = round($onedollarprof,2);
如何将所有利润加起来?这是网站,但它输出了错误的利润:http://tipmypicks.com/stats.php
答案 0 :(得分:0)
使用:
Group by id
Group by
应按列加总并与游戏ID(id列)区分开
因此,每场比赛的所有结果总结。
您应该考虑使用PDO类来维护与数据库的持久连接(如果您不使用缓存或需要实时值)
$data40 = mysql_query("SELECT sum(oddsnum / oddsden) FROM stats WHERE MONTH(date) = MONTH(CURRENT_TIMESTAMP) AND winloss = 'Win' Group by id");
$info40 = mysql_fetch_array($data40);
$onedollarwins = array_sum($info40);
$data41 = mysql_query("SELECT sum(oddsnum / oddsden) FROM stats WHERE MONTH(date) = MONTH(CURRENT_TIMESTAMP) AND winloss = 'Loss' Group by id");
$info41 = mysql_fetch_array($data41);
$onedollarloss = array_sum($info41);
$onedollarprof = $onedollarwins - $onedollarloss;
$onedollarprof = round($onedollarprof,2);