Reputation: 164
I have two tables
tblData
ID Name
1 ABC
2 XYZ
tblDetails
ID DataID PayDate Amount ApprovedDate
1 1 15-08-2015 200 20-18-2015
2 1 16-08-2015 300 20-18-2015
3 1 17-08-2015 50 20-18-2015
4 2 18-08-2015 100 21-18-2015
5 2 19-08-2015 500 21-18-2015
I need to get the result like the following
ID Duration TotalAmount ApprovedDate
1 15-08-2015 - 17-08-2015 550 20-18-2015
2 18-08-2015 - 19-08-2015 600 21-18-2015
How can I accomplish this?
Upvotes: 2
Views: 46
Reputation: 72225
It seems like a simple GROUP BY
together with some aggregate functions can do the job:
SELECT DataID, CONCAT(MIN(PayDate), ' - ', MAX(PayDAte)) AS Duration,
SUM(Amount) AS TotalAmount, MAX(ApprovedDate) AS ApprovedDate
FROM tblDetails
GROUP BY DataID
Note: Table tblData
does not seem to play any role in producing the required result set.
Upvotes: 6
Reputation: 1665
You can use joins in your query which will join data from different tables into one. Simple example
Upvotes: 0