[英]sum by id mysql in PHP
我想通过id_subkategori对所有total_harga求和,我怎么能得到? 所以只获取例如所有id_subkategori 5求和我的数据库表
您可以使用GROUP BY id_subkategori获得所需的输出。
GROUP BY id_subkategori
select sum(total_harga) total, id_subkategori from yourtable group by id_subkategori
您可以在此处阅读有关聚合函数的更多信息
编辑:
如果要选择一个特定的id_subkategori,则需要像下面这样进行更改。
select sum(total_harga) total, id_subkategori from yourtable where id_subkategori=5 group by id_subkategori
使用sql语句求和。
select sum(total_harga) total from yourtable where id_subkategori = 5 group by id_subkategori
然后通过PHP获取sql结果。 请检查此作为参考。
[英]PHP calculate sum of 2 columns in MySQL query WHERE id matches
[英]How to follow user id to get sum of MySQL column in PHP?
[英]How to update a total sum from a row based on id in php mysql
[英]php mysql join three tables and sum item of same id
[英]sum of column php/mysql
[英]MYSQL/PHP sum with group by
[英]Display mysql SUM in PHP
[英]MySQL - PHP Column Sum
[英]php mysql if sum not working
[英]Sum mysql array in PHP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.