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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:50:49+00:00 2026-06-14T09:50:49+00:00

Here is my problem: I got a table like this one: Table Log int

  • 0

Here is my problem:

I got a table like this one:

 Table Log
 int id;
 int time;
 timestamp DATE;
 int sid (FK to table Site);

and a table Site:

 Table Site;
 int id;
 varchar title;

In my log table, a site can be present 0 or N times, I need to get the sum of time for each site.

This request is done and seems to work, now I need to get the site title and the average of the sum time for a specific period in my logs.

Here is my query:

SELECT site, AVG(sumtime)
FROM (
    SELECT Site.TITLE as site, SUM(time) as sumtime FROM Log
    INNER JOIN sites ON Site.ID = Log.sid
    WHERE Log.DATE between '2012-11-13' AND '2012-11-15'
    GROUP BY Site.TITLE
) AS t1
GROUP BY t1.site;

But the average seems to not be working in this case, the value i’m getting is a the sum i’ve computed in my subquery, any help?

EDIT:

Here is a data sample:

Site
1 SiteA
2 SiteB

Log
1 2500 "2012-11-14 07:00:01" 1
2 3500 "2012-11-14 07:10:01" 1
3 4500 "2012-11-14 07:12:01" 1
4 6500 "2012-11-13 10:10:01" 1
5 2500 "2012-11-14 08:00:01" 2
6 3500 "2012-11-14 10:10:01" 2
7 5500 "2012-11-13 12:10:01" 2

What I need now is, an average on the time sum on a period (let’s say 2012-11-13 to 2012-11-14 for this example), so as for the expected datas:

Site, avg time sum
Site A, 8500
Site B, 5750
  • 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-14T09:50:50+00:00Added an answer on June 14, 2026 at 9:50 am

    I solved my problem, found the good way to write the query (thanks to @tombom):

    SELECT t1.site, AVG(sumtime)
    FROM (
        SELECT Site.TITLE as site, SUM(time) as sumtime FROM Log
        INNER JOIN Site ON Site.ID = Log.sid
        AND Log.DATE between '2012-11-14' AND '2012-11-15'
        GROUP BY site, DATE(Log.DATE)
    ) AS t1
    group by t1.site
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here i got a problem in my script, Once we set one radio button
This should be an easy one, looks like I got myself too confused. I
i am new at Java , i got a problem like this ; i
I want to ask about strcpy. I got problem here. Here is my code:
here is my problem: I've got a repeater on my asp.net (VB): <asp:Repeater ID=Repeater1
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
I've got an interesting box-model problem here. I have a header full of links,
Can't understand what is a problem here: I have got main.cpp file where I
Here's the problem. I've got two different technologies needing drivers to access a PostgreSQL
I've got a problem using different layouts for list items in my project. Here

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.