rai
  • Posts: 92
  • Joined: 23/02/2008
Can somebody help me with creating a query that is grouping number of Thanks by email. I would like to reward the most thanked users so I need to generate a list.

Thanks!

Sponsor
Zero2Cool
  • Posts: 1083
  • Joined: 26/04/2011
Here's what I use to get the most X thanks by userID for the last 7 days. Just remove the where clause and well whatever ya want. This should help you get going.

DECLARE @Topper INT = @Top
   
   SELECT TOP (@Topper) yaf_User.UserID, yaf_User.Name, COUNT(ThanksToUserID) as Total
   FROM yaf_Thanks 
   INNER JOIN yaf_User 
   ON yaf_Thanks.ThanksToUserID = yaf_User.UserID 
   INNER JOIN yaf_Message
   ON yaf_Message.MessageID = yaf_Thanks.MessageID
   INNER JOIN yaf_Topic
   ON yaf_Topic.TopicID = yaf_Message.TopicID
   WHERE yaf_Thanks.ThanksDate > DATEADD(DAY, -7, GETDATE()) 
   GROUP BY yaf_Thanks.ThanksToUserID, yaf_User.Name, yaf_user.UserID
   ORDER BY COUNT(ThanksToUserID) DESC

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved