I have the following data set.
[Date Recorded] [VoteID] [User]
[2012-07-20 00:00:00.000] [2] [A]
[2012-07-20 00:00:00.000] [3] [B]
[2012-07-20 00:00:00.000] [4] [C]
[2012-07-24 00:00:00.000] [1] [A]
[2012-07-24 00:00:00.000] [1] [B]
How can I get it to count the vote sum. If we look at 2012-07-24 there are 2 users who recorded a vote of [1] so how can I get these two users to add up. So it would look something like
[Date Recorded] [VoteID] [Count]
[2012-07-20 00:00:00.000] [2] [1]
[2012-07-20 00:00:00.000] [3] [1]
[2012-07-20 00:00:00.000] [4] [1]
[2012-07-24 00:00:00.000] [1] [2]
I have a Guid for the UserID as well as the VoteID.
Can someone help?
Group on [Date Recorded]
and VoteID
:
SELECT [Date Recorded], VoteID, COUNT(*) [Count]
FROM YourTable
GROUP BY [Date Recorded], VoteID
The GUID for your user who voted is irrelevant since you just want to know how many people voted a certain way on a given date; you don't need specific user details in this aggregate.
Use GROUP BY
to group by both the date and id column, then COUNT
up the results in each group:
SELECT [Date Recorded], VoteID, COUNT(*)
FROM myTable
GROUP BY [Date Recorded], VoteID
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