MySQLi列总和适用于一个查询,但不适用于另一个查询

时间:2019-03-08 12:36:58

标签: php mysql mysqli

我正在尝试对一列的总和求和。...

我可以将其用于其他列的求和,但是该列不会求和,并且我没有得到回显的值。

任何人都建议,为什么列收益的格式与利润完全相同(小数5,2)

PHP-可以使用

 <div class="col-md-2 col-md-2-2">
                    <div class="card mt-5">
                        <div class-title>
                        <h3 role="button" class="bg-secondary text-white text- 
   center py-3">Stake Placed<br></h3>                           
                        </div>
                        <div class="card-body">
    <table class='table table-bordered'>
    <?php

    $connection = mysqli_connect("******", "******", 
    "******", "******");
    if (!$connection) {
        die("Database connection failed: " . mysqli_connect_error());
    }

             $Date = '2019-03-11'; 

    $ssql="SELECT sum(stakePlaced) as total FROM bets WHERE betDate = '$Date'";


    $sresult = mysqli_query($connection, $ssql);

    while ($srow = mysqli_fetch_assoc($sresult))
    { 
    echo "<tr>";
    echo "<td class='text-center'>£".$srow['total'] . "</td>";
    echo "</tr>";
    }

    mysqli_close($connection);
    ?>
    </table>
                        </div>


                    </div>
                </div> 

PHP-不起作用

            <div class="col-md-2 col-md-2-2">
                    <div class="card mt-5">
                        <div class-title>
                        <h3 role="button" class="bg-secondary text-white text- 
    center py-3">Actual Return<br></h3>                         
                        </div>
                        <div class="card-body">
    <table class='table table-bordered'>
    <?php

    $connection = mysqli_connect("******", "******", 
    "******", "******");
    if (!$connection) {
        die("Database connection failed: " . mysqli_connect_error());
    }

             $Date = '2019-03-11'; 

    $test = "SELECT sum(return) as total FROM bets WHERE betDate = '$Date'";

    $testr = mysqli_query($connection, $test);

    while ($testrow = mysqli_fetch_assoc($testr)) 

    { 
    echo "<tr>";
    echo "<td class='text-center'>£".$testrow['total'] . "</td>";
    echo "</tr>";
    }

    mysqli_close($connection);
    ?>
    </table>

result screenshot table screenshot

1 个答案:

答案 0 :(得分:0)

return是mysql中的保留关键字。更改列名称,或者在使用该列名称时都应使用刻度线

sum(`return`)