Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MadJoker
Starting Member
2 Posts |
Posted - 2009-06-28 : 09:32:32
|
| Hi,I have the following problem: I have a table that looks something like this:Date User Actions01/01/09 1 1002/02/09 1 2304/04/10 1 1205/05/10 2 15What I want to do is create a view that shows how many actions a user made per year. So the expected result would be something like this:Year User Actions09 1 3310 1 1210 2 15I know how to get the year out of the date. So my idea was to simply sum up the values in every row where year and user a the same, but I have no idea how to do this, so any help would be appreciated.MadJoker |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-28 : 09:41:25
|
[code]select [year] = datepart(year, [Date]), User, Actions = sum(Action)from tablegroup by datepart(year, [Date]), User[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
MadJoker
Starting Member
2 Posts |
Posted - 2009-06-28 : 10:25:05
|
| Thanks man, worked perfectly. The group by function was, what I was looking for. |
 |
|
|
|
|
|