SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating stats

    I have made a little portal for my department at work. People can add news, links, quotes, etc. However, I want to make a stats page to display who has submitted the most to each category. For example, how would I structure a query to pull the top 10 users (and the total number) who have submitted to the links section?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select username
         , count(*) as submissions
      from yourtable
     where category = 'links'
    group
        by username
    order
        by submissions desc
    limit 10
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I should have explained my database setup:

    LINKS

    link_id
    link_name
    link_url
    link_user_id -- user who submitted link

    USERS

    user_id
    user_name

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select users.user_name
         , count(*) as submissions
      from links
    inner
      join users
        on links.link_user_id
         = users.user_id
    group
        by user_name
    order
        by submissions desc
    limit 10
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •