SQL sum and number

微信扫一扫,分享到朋友圈

SQL sum and number

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.

微信扫一扫,分享到朋友圈

SQL sum and number

iPhone X IP67 Water-Resistant Explained: Here’s What It Really Means

上一篇

You Have No Control Over Your Data, Even Your DNA

下一篇

你也可能喜欢

SQL sum and number

长按储存图像,分享给朋友