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 8182385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:50:51+00:00 2026-06-07T00:50:51+00:00

I have a website that is mirrored cross two sub-domains. So I have separate

  • 0

I have a website that is mirrored cross two sub-domains. So I have separate analytics datasets for both.
I have the following tables:

|------------------------------|
| table_a                      |
|------------------------------|
| url             | mod_date   |
|------------------------------|
| /foo/index.html | 2009-10-24 |
| /bar/index.php  | 2010-01-04 |
| /foo/bar.html   | 2009-01-04 |
|------------------------------|

|-----------------------------------------|
| table_b                                 |
|-----------------------------------------|
| url             | views | access_date   |
|-----------------------------------------|
| /foo/index.html | 35000 | 2009-12-01    |
| /foo/index.html | 20000 | 2010-02-01    |
| /bar/index.php  | 35000 | 2010-01-01    |
| /bar/index.php  | 15000 | 2011-01-01    |
|-----------------------------------------|

|-----------------------------------------|
| table_c                                 |
|-----------------------------------------|
| url             | views | access_date   |
|-----------------------------------------|
| /foo/index.html | 35000 | 2009-10-01    |
| /foo/bar.html   | 10000 | 2011-05-01    |
| /bar/index.php  | 35000 | 2011-08-01    |
| /bar/index.php  | 15000 | 2012-04-01    |
|-----------------------------------------|

I have the following query:

SELECT 
    a.url
    ,DATE_FORMAT(a.mod_date, '%d/%m/%Y') AS 'mod_date'
    ,DATE_FORMAT(MIN(b.access_date), '%d/%m/%Y') AS 'first_date'
    ,DATE_FORMAT(MAX(b.access_date), '%d/%m/%Y') AS 'last_date'
    ,SUM(ifnull(b.pages,0)) + SUM(ifnull(c.pages,0)) AS 'page_views'    
    ,DATEDIFF(MAX(b.access_date),MIN(b.access_date)) AS 'days'
    ,ROUND(SUM(b.pages) / (DATEDIFF(MAX(b.access_date),MIN(b.access_date)) / 30.44)) AS 'b_mean_monthly_hits'
    ,ROUND(SUM(c.pages) / (DATEDIFF(MAX(c.access_date),MIN(c.access_date)) / 30.44)) AS 'a_mean_monthly_hits'
FROM
    tabl_a a
        LEFT JOIN
    table_b b ON b.url = a.url
        LEFT JOIN
    table_c c ON c.url = a.url
GROUP BY a.url
HAVING ROUND(SUM(b.pages) / (DATEDIFF(MAX(b.access_date),MIN(b.access_date)) / 30.44)) < 5
AND ROUND(SUM(c.pages) / (DATEDIFF(MAX(c.access_date),MIN(c.access_date)) / 30.44)) < 5
;

The result I’m looking for is:

|------------------------------------------------------------------------------------------|
| results                                                                                  |
|------------------------------------------------------------------------------------------|
| url             | mod_date   | first_date | last_date  | page_views   | avg_monthly_hits |
|------------------------------------------------------------------------------------------|
| /foo/index.html | 2009-10-24 | 2009-10-01 | 2010-02-01 | 90000        | 22273            |
| /bar/index.php  | 2010-01-04 | 2010-01-01 | 2012-04-01 | 85000        | 3275             |
| /foo/bar.html   | 2009-01-04 | 2011-05-01 | 2011-06-01 | 10000        | 9819             |
|------------------------------------------------------------------------------------------|

Where ‘avg_monthly_hits’ is the sum of b.views and c.views (as ‘page_views’) divided by the number of days (don’t know how to get the months) between the oldest and newest access_date from table_b or table_c divided by 30.44 (the average number of days in a month).

I hope that I have explained myself fully. 🙂

  • 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-06-07T00:50:52+00:00Added an answer on June 7, 2026 at 12:50 am

    In the end a nested query solved the problem.

    SELECT DISTINCT a.url
    , q.mod_date
    , IF(q.b_min_date < q.c_min_date, q.b_min_date, q.c_min_date) AS 'min_date'
    , IF(q.b_max_date > q.c_max_date, q.b_max_date, q.c_max_date) AS 'max_date'
    , (PERIOD_DIFF(DATE_FORMAT(IF(q.b_max_date > q.c_max_date, q.b_max_date, q.c_max_date), '%Y%m'),DATE_FORMAT(IF(q.b_min_date < q.c_min_date, q.b_min_date, q.c_min_date), '%Y%m')) + 1) AS 'months'
    , q.page_views
    , ROUND(q.page_views / ((PERIOD_DIFF(DATE_FORMAT(IF(q.b_max_date > q.c_max_date, q.b_max_date, q.c_max_date), '%Y%m'),DATE_FORMAT(IF(q.b_min_date < q.c_min_date, q.b_min_date, q.c_min_date), '%Y%m'))) + 1)) AS 'avg_monthly_hits'
    FROM table_a a
    INNER JOIN
        (SELECT 
                a.url,
                    a.date AS 'mod_date',
                    MIN(b.date) AS 'b_min_date',
                    MAX(b.date) AS 'b_max_date',
                    MIN(c.date) AS 'c_min_date',
                    MAX(c.date) AS 'c_max_date',
                    SUM(ifnull(b.pages, 0)) + SUM(ifnull(c.pages, 0)) AS 'page_views'
            FROM
                table_a a
                    LEFT JOIN
                table_b b ON a.url = b.url
                    LEFT JOIN
                table_c c ON a.url = c.url
            GROUP BY a.url
    ) q
    ON a.url = q.url
    WHERE ROUND(q.page_views / ((PERIOD_DIFF(DATE_FORMAT(IF(q.b_max_date > q.c_max_date, q.b_max_date, q.c_max_date), '%Y%m'),DATE_FORMAT(IF(q.b_min_date < q.c_min_date, q.b_min_date, q.c_min_date), '%Y%m'))) + 1)) < 5
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have website that will both post to a user's Facebook wall, and allow
So basically I have website that has names of cities that can be checked
I have a website that is mainly based on JavaScript. It uses a REST
I have a website that logs in using an STS, then gets a delegated
I have a website that in a few months is going to have traffic
I have a website that includes a few loading Gifs that spin while certain
I have a website that runs fine on IE10 Consumer Preview, Chrome, and Firefox
I have a website that is hosted on Godaddy server. For SEO I have
I have a website that has highly granulised access and hence requires many web.config
I have a website that contains company profiles. These profiles have many pages within

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.