我在以下结构中有一个日常表格,其中包含数据
+----+----------+-------+---------+
| 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
总计。如下所示。
+----+----------+-------+---------+
| 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 |
+----+----------+-------+---------+--------------+
我希望有人之前已经解决了这样的问题。请分享一些想法。
答案 0 :(得分:2)
你试过了吗?
select *,sum(daily_amt) from dailyentry group by date, loan_id