[英]sum by id mysql in PHP
i want to sum all total_harga by id_subkategori, how i caan get that? 我想通过id_subkategori对所有total_harga求和,我怎么能得到? so just get for example all id_subkategori 5 get sum my database table
所以只获取例如所有id_subkategori 5求和我的数据库表
You can use GROUP BY id_subkategori
to get the desired output. 您可以使用
GROUP BY id_subkategori
获得所需的输出。
select sum(total_harga) total, id_subkategori
from yourtable
group by id_subkategori
You can read more on aggregate functions here 您可以在此处阅读有关聚合函数的更多信息
Edit: 编辑:
If you want to pick for a specific id_subkategori, you need to change it like following. 如果要选择一个特定的id_subkategori,则需要像下面这样进行更改。
select sum(total_harga) total, id_subkategori
from yourtable
where id_subkategori=5
group by id_subkategori
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.