I have a table structure like this :
ID commission transdate token
1 10 2013-11-22 08:24:00 token1
2 10 2013-11-22 08:24:00 token1
3 10 2013-11-22 08:24:00 token1
4 10 2013-11-22 08:24:00 token1
5 10 2013-11-22 08:24:00 token1
6 29 2013-11-22 06:24:00 token2
7 29 2013-11-22 06:24:00 token2
The thing is that I have duplicate entries in my table for some data and I need to filter it out while taking the SUM. If the transdate is same and the token is same, I only need to consider one entry for the sum. The sum I need is sum of all the commission for all token grouped by date.
How can I do this through query ?
Use DATE with GROUP BY:
SELECT
SUM(comission),
token,
DATE(transdate)
FROM
t
GROUP BY
token,
DATE(transdate)
try below query,
To consider only one entry for date for a particular token:
SELECT commission,
date(transdate),
token
FROM tokens
GROUP BY date(transdate),
token;
To get a sum of commission for date
SELECT SUM(commission),
DATE(transdate),
token
FROM tokens
GROUP BY DATE(transdate),
token;
Sql Fiddle Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With