gpt4 book ai didi

php - 选择两列并计算它们的数量

转载 作者:行者123 更新时间:2023-11-29 17:54:59 28 4
gpt4 key购买 nike

我制作一张表格,并且我想制作按 desc 排序的表格,

示例:采用 Bank_Account + HandMoney = SUM,并在 Desc 中写出其总和

我已经只用“HandMoney”制作了表格,效果很好,但我真的不知道如何计算两列的总和

对我现在拥有的进行编码:

        $query = $connection -> prepare("SELECT `p_name`, `HandMoney` FROM `users` ORDER BY `HandMoney` DESC LIMIT 15"); 

if($query -> execute())
{
if($query -> rowCount())
{
$count = 0;

?>
<thead>
<table class="table-fill2">
<tbody class="table-hover">
<tr>
<th class="text-left">
Postion
</th>

<th class="text-left">
Player Name
</th>

<th class="text-left">
Money
</th>
</tr>
</thead>
<tbody class="table-hover">
<?php

while($query_result = $query -> fetch())
{
?>

<tr>
<td style = "text-left">
<?php

echo ++ $count;

?>
</td>

<td style = "text-left">
<?php

echo $query_result['p_name'];

?>
</td>

<td style = "text-left">
<?php

echo number_format($query_result['HandMoney']);

?>
</td>
</tr>

<?php
}

?>
</tbody>
</table>

<?php
}
else
{
echo 'No players were found.';
}
}

?>

所以我想取两列(HandMoney + BankMoney = SUM)并按该总和对玩家进行排序

最佳答案

如果我理解正确的话,你想要这样:

SELECT `p_name`, SUM(Bank_Account + HandMoney) as BandH
FROM `users`
GROUP BY p_name
ORDER BY BandH DESC

关于php - 选择两列并计算它们的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48937643/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com