Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3315454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:21:08+00:00 2026-05-17T22:21:08+00:00

Figuring out a title for this question was hard, but the following is harder

  • 0

Figuring out a title for this question was hard, but the following is harder for me. I hope anyone can help.

I have a simple MySQL database table. This table is filled with records containing an ID and the number of week-visitors. It has records of 2 year of about 200+ websites.

To summarize, I want to be able to know two things:

1.) – “In week 54 of 2009 the website somethingonline.com had 300 visitors” (Easy of course. I can do this)

2.) – “The webiste sometingonline.com was among the 8% best scoring websites in that week.”

Now, how can I get number 2.??? Of course, I want to know that percentage of all websites in every week so I get a list like:

  1. sometingonline1.com – 300 visitors – 8% of the website score like this or better
  2. sometingonline2.com – 400 visitors – 4% of the website score like this or better
  3. sometingonline3.com – 500 visitors – 2% of the website score like this or better
  4. sometingonline4.com – 600 visitors – 1% of the website score like this or better

How can I get these results? Is this possible in one query?

I use MySQL and PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:21:08+00:00Added an answer on May 17, 2026 at 10:21 pm

    The key is to involve two different “copies” of your visits table. In this query v1 represents the website you’re actually looking at. For each of those v1 websites, we’ll join to a copy of the visits table, matching any row that covers a site with more visits in the same week.

    SELECT v1.website_name, v1.visits, COUNT(v2.id)
    FROM visits AS v1
    INNER JOIN visits AS v2 ON (v1.week_number = v2.week_number AND v2.visits > v1.visits AND v2.id != v1.id)
    WHERE week_number = 54
    

    This will tell you the number of sites that had more visitors. To get that as a percentage, run a separate query to simply count the total number of sites that had any visits in that week. In your PHP script you can then do the simple division to get the percentage you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was having a hard time figuring out a good title for this question,
I have trouble figuring out why a simple division like this one always returns
Having a hard time figuring out why this alert code is being called once
I need help figuring this out, what am I doing wrong my book doesn't
I had some problems figuring out a good title, but hopefully the code examples
I edited this after figuring out a few things but is this a good
Can anyone suggest a suitable way of figuring out a pieces allowable moves on
I'm having trouble figuring out how to filter a queryset appropriately for the following
I am having trouble figuring out how to implement this. I am returning user
I'm having a hard time figuring out how to access a group of UIButton

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.