counting distinct posts by a users within the past 10 days - SQL2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssasser
    New Member
    • Dec 2007
    • 2

    counting distinct posts by a users within the past 10 days - SQL2005

    Hey gang, any help will be apprecited. I am trying to do a simple count of all posts to a message board from a few particular users within the past 10 days.

    I know the usernames and number of days that i want to query (10) and I want the output to display as follows....
    Manager PostCount
    user1 1
    user2 14
    user3 20
    _______________ ____

    The query i have is but below but there is two problems with it. They are not being grouped but rather outputing lineitem AND the DATEADD criteria does not seem to affect the result.

    Code:
    SELECT     PostAuthor, COUNT(PostAuthor) AS PM_Count
    FROM         cs_Posts
    GROUP BY PostAuthor, PostDate
    HAVING      (PostDate = DATEADD(d, - 10, GETDATE())) AND (PostAuthor = N'dclecompte') OR
                          (PostAuthor = N'haley') OR
                          (PostAuthor = N'clapoint')
    ORDER BY PostDate DESC, PostAuthor
    I am a new guy so I really do appreciate any help that you can provide.
  • ssasser
    New Member
    • Dec 2007
    • 2

    #2
    TRY THIS

    Code:
    SELECT     COUNT(PostAuthor) AS PM_Post_Count, PostAuthor
    FROM         dbo.cs_Posts
    WHERE     (PostDate = DATEADD(d, - 10, GETDATE())) OR
                          (PostAuthor = N'haley') OR
                          (PostAuthor = N'clapoint') OR
                          (PostAuthor = N'dclecompte')
    GROUP BY PostAuthor

    Originally posted by ssasser
    Hey gang, any help will be apprecited. I am trying to do a simple count of all posts to a message board from a few particular users within the past 10 days.

    I know the usernames and number of days that i want to query (10) and I want the output to display as follows....
    Manager PostCount
    user1 1
    user2 14
    user3 20
    _______________ ____

    The query i have is but below but there is two problems with it. They are not being grouped but rather outputing lineitem AND the DATEADD criteria does not seem to affect the result.

    Code:
    SELECT     PostAuthor, COUNT(PostAuthor) AS PM_Count
    FROM         cs_Posts
    GROUP BY PostAuthor, PostDate
    HAVING      (PostDate = DATEADD(d, - 10, GETDATE())) AND (PostAuthor = N'dclecompte') OR
                          (PostAuthor = N'haley') OR
                          (PostAuthor = N'clapoint')
    ORDER BY PostDate DESC, PostAuthor
    I am a new guy so I really do appreciate any help that you can provide.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Originally posted by ssasser
      TRY THIS

      Code:
      SELECT     COUNT(PostAuthor) AS PM_Post_Count, PostAuthor
      FROM         dbo.cs_Posts
      WHERE     (PostDate = DATEADD(d, - 10, GETDATE())) OR
                            (PostAuthor = N'haley') OR
                            (PostAuthor = N'clapoint') OR
                            (PostAuthor = N'dclecompte')
      GROUP BY PostAuthor
      Is it working now or still facing an issue??

      Comment

      Working...