1
兩個條件我有一個數據組通過在MySQL查詢
+----+----------+-------+---------+
| id | date |loan_id|daily_amt|
+----+----------+-------+---------+
| 1 |20-07-2014| 1 | 200 |
| | | | |
| 2 |20-07-2014| 1 | 300 |
| | | | |
| 3 |20-07-2014| 2 | 400 |
| | | | |
| 4 |20-07-2014| 2 | 200 |
| | | | |
| 5 |21-07-2014| 1 | 100 |
+----+----------+-------+---------+
我需要每天daily_amt
總每個loan_id
在這個結構如下表dailyentry。如下所示。
+----+----------+-------+---------+
| id | date |loan_id|daily_amt|
+----+----------+-------+---------+
| 1 |20-07-2014| 1 | 500 |
| | | | |
| 3 |20-07-2014| 2 | 600 |
| | | | |
| 5 |21-07-2014| 1 | 100 |
+----+----------+-------+---------+
我試圖通過groub by date
得到它。這樣下面,
select *,sum(daily_amt) from dailyentry group by date
此查詢結果被示出像下面。
+----+----------+-------+---------+--------------+
| id | date |loan_id|daily_amt|sum(daily_amt)|
+----+----------+-------+---------+--------------+
| 1 |20-07-2014| 1 | 500 | 1100 |
| | | | | |
| 5 |20-07-2014| 1 | 100 | 100 |
+----+----------+-------+---------+--------------+
我希望有人已經解決過這樣的問題了。請分享一些想法。
想要通過兩個元素gorup? – user28470 2014-10-01 12:50:52
yes ...按日期以及loan_id – 2014-10-01 12:51:35