[英]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.