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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:00:38+00:00 2026-05-10T21:00:38+00:00

SELECT avg(con_hits) as avg_hits FROM content WHERE con_type = 1 AND con_posttime < $twelve_hrs_ago

  • 0
SELECT    avg(con_hits) as avg_hits  FROM    content  WHERE    con_type = 1    AND con_posttime < $twelve_hrs_ago    AND con_refresh = 0  ORDER BY    con_posttime DESC  LIMIT 100 

I would like it to go to the first record that was posted at least 12 hours ago (denoted by the $twelve_hrs_ago variable which has the suitable timestamp), and take the average of the con_hits column, for the next 100 records. In my example, it disregards the LIMIT, and takes the average of every record in the table.

Is there a way to bypass that?

  • 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. 2026-05-10T21:00:39+00:00Added an answer on May 10, 2026 at 9:00 pm

    LIMIT is applied to the resultset, after AVG is calculated. You can do what you want, with a subselect:

    SELECT avg(con_hits) as avg_hits FROM (   SELECT con_hits   FROM content   WHERE     con_type = 1     AND con_posttime < $twelve_hrs_ago     AND con_refresh = 0   ORDER BY con_posttime DESC   LIMIT 100 ) x; 

    You can use the database to calculate the time offset too. Replace $twelve_hrs_ago above with:

    date_add(now(), interval -12 hour) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This: SELECT AVG(LENGTH(string)) FROM BLAH LIMIT 10; ...seems to grind through all results. If
SELECT AVG(data) AS data, dateReg FROM table GROUP BY YEAR(dateReg), MONTH(dateReg), DAY(dateReg) ORDER BY
SELECT AVG(variable) AS Expr1, SUM(variable) AS Expr2 FROM ...... result for AVG is 2,
How can you write the following in MYSQL? SELECT AVG(col1) FROM table WHERE DISTINCT
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have a basic group by/avg statement: select url, avg(contentping+tcpping), count(*) from websites ws,
SELECT Output.name, Output.avgSalary FROM (SELECT Airplane.aid, Airplane.aname AS name, AVG (worker.salary) AS avgSalary FROM
My current query reads: SELECT entry_id, user_id, cat_id, AVG( rating ) as avg_rate FROM
SELECT Id,Date,Name FROM people WHERE DATEPART(hh,Date) >= 7 AND DATEPART(hh,Date) <= 8 Order by
SELECT AVG(`col5`) FROM `table1` WHERE `id` NOT IN ( SELECT `id` FROM `table2` WHERE

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.