Need help, friends. :)
Could you help me, please.
So, i've a table on mySQL. Preview like this :
MyDate phone name costA costB
2011-09-13 0767657567567 Xyz 35 30
2011-09-24 0767657567567 Xyz 10 15
2011-09-26 0767657567567 Xyz 25 15
2011-09-27 081323232323 Abc 20 25
I want to make the query that execute by condition WHERE MONTH(MyDate) = '9'
and result like this :
phone 开发者_如何转开发 name sum(costA) sum(costB)
0767657567567 Xyz 70 60
081323232323 Abc 20 25
Coudl you tell me how the query of the result above?
use
SELECT
MONTH(MyDate),
phone,
name,
sum(costA),
sum(costB)
FROM MyTable
WHERE MONTH(MyDate) = '9'
GROUP BY MONTH(MyDate), phone, name
I'm not too sure but you can try the following:
SELECT phone, name, sum(costA), sum(costB)
FROM table
WHERE MONTH(MyDate) = 9
GROUP BY phone, name
It's basically a simple GROUP BY clause that can do the sum according to the name that appears and if the month is 9. Let me know if it works.
精彩评论