SQL Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rchelifan
    Member
    • Jul 2007
    • 74
    • 3.6.x

    SQL Query

    Hi folks,
    I am not good at SQL and wondering if someone can help me to write an SQL query to look for users that have posted X number from X date. For example, I like to know who have posted 30 posts since 02/01/2009. I hope someone here can help with with this.
    I love RC helicopter hobby
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    #2
    Here are some queries like this:

    Comment

    • rchelifan
      Member
      • Jul 2007
      • 74
      • 3.6.x

      #3
      Thanks for the link. I'll see if I can change it to have it work with mine query.
      I love RC helicopter hobby

      Comment

      • Lats
        Senior Member
        • Mar 2002
        • 3671

        #4
        See if this works for you...
        Code:
        SELECT 
            COUNT(postid) AS count, 
            user.username AS username
        FROM 
            post
        LEFT JOIN 
            user 
        ON 
            (user.userid = post.userid)
        WHERE
            dateline > unix_timestamp('2009-01-02')
        GROUP BY 
            username
        HAVING
            COUNT(postid) > 30
        ORDER BY 
            count 
        DESC
        Lats...

        Comment

        • rchelifan
          Member
          • Jul 2007
          • 74
          • 3.6.x

          #5
          Originally posted by Lats
          See if this works for you...
          Code:
          SELECT 
              COUNT(postid) AS count, 
              user.username AS username
          FROM 
              post
          LEFT JOIN 
              user 
          ON 
              (user.userid = post.userid)
          WHERE
              dateline > unix_timestamp('2009-01-02')
          GROUP BY 
              username
          HAVING
              COUNT(postid) > 30
          ORDER BY 
              count 
          DESC
          It works perfectly. I only needed to add the table prefix. Thanks a lot!
          I love RC helicopter hobby

          Comment

          • rchelifan
            Member
            • Jul 2007
            • 74
            • 3.6.x

            #6
            Can someone help me refine this query again? After runing a couple more times, it seems like the query brings some people who don't have 30 or more posts whithin the month. Thanks a lot folks!
            I love RC helicopter hobby

            Comment

            • Lats
              Senior Member
              • Mar 2002
              • 3671

              #7
              Are you adjusting the date reference?

              Might have to add hours & minutes to the test.
              Lats...

              Comment

              • rchelifan
                Member
                • Jul 2007
                • 74
                • 3.6.x

                #8
                Yes, but it seems like it also brings those who don't have more than 30 posts but posted two or three in the month. It seems like COUNT(postid) > 30 is not date limited.
                I love RC helicopter hobby

                Comment

                • Lats
                  Senior Member
                  • Mar 2002
                  • 3671

                  #9
                  Are you saying the count column in the results have numbers less than 30?
                  Lats...

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...