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

  • Home
  • SEARCH
  • 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 6150903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:41:22+00:00 2026-05-23T19:41:22+00:00

I have a log table in my database which holds all user actions. In

  • 0

I have a log table in my database which holds all user actions. In this table there is a column called ‘money’ which indicates how much money this user had on that day (there is also a ‘timestamp’ column for each log entry)

How can I retrieve data from that table grouped by week or month, aggregated with average value for money?

  • 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-23T19:41:23+00:00Added an answer on May 23, 2026 at 7:41 pm

    The easiest way to do this would be to precalculate the week and/or month and store that data into another field. Then the query is as easy as YourTable.objects.values('week', 'year').annotate(Avg('money)).

    You should also be able to do this with extra() parameters, but that is sometimes tricky. That would look like

    YourTable.objects.extra(select={
         'week': 'some_method_to_calculate_week_from_timestamp(timestamp)'
    }).values('week').annotate(Avg('money'))
    

    How you would calculate the week from timestamp in this second case would depend on your DB. If postgres the information you need would be in here: http://www.postgresql.org/docs/8.1/static/functions-datetime.html

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

Sidebar

Related Questions

I have an Oracle table which contains event log messages for an application. We
I have a couple of tables which are used to log user activity for
I have a table in my database which essentially serves as a logging destination.
I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
I am designing a table in the database which will store log entries from
I have this error: 12-07 15:27:11.567: E/AndroidRuntime(15797): Caused by: android.database.sqlite.SQLiteException: no such column: recipient:
I have to meet the requirement to log on a database all the requests
I have a database with log entries, like: CREATE TABLE `cheaters` ( `id` bigint(20)
I have a table that contains log entries for a program I'm writing. I'm
I have a table that functions as an event log and stores the users

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.