开发者

MySQL: I want to sum my employees cost and group it by employee and by day

I currently have a table where I record all my employee daily expenses

John Smith    01 JAN 2010    200$ 
John Smith    01 JAN 2010    50$
John Smith    01 JAN 2010    10$
Lady Gaga开发者_如何学Python     01 JAN 2010    50$ 
Lady Gaga     01 JAN 2010    20$
John Smith    02 JAN 2010    10$

What I would like to display a table that contains a daily report of all bills:

01 JAN 2010
John Smith: 260$
Lady Gaga: 70$

02 JAN 2010
John Smith: 10$

I really hope my request is understandable and you will be able to help me.

Thank a lot for any advice!


I would use a standard group-by:

select date, name, sum(amount) as total
from mytable
group by 1,2
order by 1,2;


use SUM with GROUP BY , do something like

SELECT date,user,SUM(cost)
FROM mytable
GROUP BY  date,user
ORDER BY  date
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜