gpt4 book ai didi

php - 如何计算 pf 以及如何显示 pf 总量

转载 作者:行者123 更新时间:2023-11-28 23:19:23 26 4
gpt4 key购买 nike

这里我要计算PF,我们每个月都要扣pf,现在我要显示pf的总金额,这是我的数据库表结构

id    first_name   pf_amount   pf_month    badge_number

1 Kani 200 01-2017 01

2 Mahesh 250 01-2017 02

3 Kani 200 02-2017 01

4 Mahesh 250 02-2017 02

在我的列表页面中,我想显示 badge_number (01) 有 400 和 badge_number (02) 有 500。这里 badge_number 是唯一的

我这样写了查询,但在这里我得到了所有数据,如何根据我的要求做

$check = mysql_query("SELECT * FROM pf_history");
while($row = mysql_fetch_array($check)) {
echo $row['pf_amount'];
}

最佳答案

在查询中使用 GROUP BY AND SUM():

SELECT first_name, pf_month, SUM(pf_amount) as total FROM pf_history GROUP BY badge_number

代码:

$check = mysqli_query("SELECT first_name, pf_month, SUM(pf_amount) as total FROM pf_history GROUP BY badge_number");
while($row = mysqli_fetch_array($check)) {
echo $row['total'];
}
group by 和 sum() 的

引用:

GROUP BY

SUM()

关于php - 如何计算 pf 以及如何显示 pf 总量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42479533/

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