我對PHP/MySQL沒有太多經驗。我有一個有3個字段的表格:id
,particular
和amount
,如下所示。顯示結果行組和總和各組值
id particular amount
1 Fees 5000
2 Fees 3000
3 Bill 9000
4 Fees 4000
5 Bill 3000
6 Expense 2000
7 Fees 1000
我要顯示在組中的數據以及每個單獨組的總和,就像這樣:
particular amount
Fees 5000
Fees 3000
Fees 4000
Fees 1000
**Total 13000**
Bill 9000
Bill 3000
**Total 12000**
Expense 2000
**Total 2000**
我嘗試此查詢SELECT SUM(amount), particular FROM sale_expense GROUP BY particular
,並添加了所有的值,但它是該組中沒有顯示,因爲我需要顯示數據
你看了'GROUP BYMySQL文檔中的「0 WITH ROLLUP」選項? – Barmar