Reputation: 2630
I have a table dailyentry in this following structure with data
+----+----------+-------+---------+
| 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 |
+----+----------+-------+---------+
I need to get each day daily_amt
total for each loan_id
. like this below.
+----+----------+-------+---------+
| id | date |loan_id|daily_amt|
+----+----------+-------+---------+
| 1 |20-07-2014| 1 | 500 |
| | | | |
| 3 |20-07-2014| 2 | 600 |
| | | | |
| 5 |21-07-2014| 1 | 100 |
+----+----------+-------+---------+
I tried to get it by groub by date
. like this below,
select *,sum(daily_amt) from dailyentry group by date
This query result is showing like below.
+----+----------+-------+---------+--------------+
| id | date |loan_id|daily_amt|sum(daily_amt)|
+----+----------+-------+---------+--------------+
| 1 |20-07-2014| 1 | 500 | 1100 |
| | | | | |
| 5 |20-07-2014| 1 | 100 | 100 |
+----+----------+-------+---------+--------------+
I hope some one already solve problem like this before. Please share some ideas.
Upvotes: 1
Views: 49
Reputation: 69440
Have you tried:
select *,sum(daily_amt) from dailyentry group by date, loan_id
Upvotes: 2