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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:44:31+00:00 2026-05-31T12:44:31+00:00

I have a table Orders with order_date and order_total . Is it possible to

  • 0

I have a table Orders with order_date and order_total. Is it possible to find out how much was averaged ordered per month?

=== ORDER_DATE === ORDER_TOTAL
--- 7-JAN-10   --- 5271
--- 12-JAN-10  --- 3646
--- 15-JAN-10  --- 310
--- 5-FEB-10   --- 71173
--- 12-FEB-10  --- 45175
--- 25-FEB-10  --- 126

In this case it would be:

JAN - 3075.66667 // calculation: (5271 + 3646 + 310) / 3
FEB - 38824.6667 // calculation: (71173 + 45175 + 126) / 3
  • 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-31T12:44:32+00:00Added an answer on May 31, 2026 at 12:44 pm

    You’ll want to reduce each date to its month. The TRUNC() function below will return the first day of the month for each date. AVG() is an aggregate function, so you’ll want to GROUP BY the month.

    SELECT TRUNC(order_date, 'MM') AS order_month, AVG(order_total) AS order_avg
      FROM orders
     GROUP BY TRUNC(order_date, 'MM')
    

    Another way to accomplish this with analytic/window functions (this way you can return all the order data along with the average per month) would be as follows:

    SELECT order_date, order_total, AVG(order_total) OVER (PARTITION BY TRUNC(order_date, 'MM'))
      FROM orders
    

    The OP asked the following:

    In the order order_month column I get something like 01-JAN-10 or
    01-FEB-10. Is it also possible, to change it to FEB-10? Just without
    the day.

    I had suggested using TO_CHAR() with a mask of ‘MON-YY’ in this case but this meant that he could no longer sort properly on that column since it was now a string and not a date. One way to handle this would be as follows:

    SELECT TO_CHAR(order_month, 'MON-YY'), order_avg
      FROM (
        SELECT TRUNC(order_date, 'MM') AS order_month, AVG(order_total) AS order_avg
          FROM orders
         GROUP BY TRUNC(order_date, 'MM')
         ORDER BY order_month
     )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a table Orders with fields CustomerID , OrderID and OrderDate ,
In MS Transact SQL, let's say I have a table (Orders) like this: Order
I have one table orders with a foreing key ProductID. I want to show
I have an orders table with a schema like this. CREATE TABLE orders (
I have an Orders table (simplified) OrderId, SalesPersonId, SaleAmount, CurrencyId, ... I am attempting
Suppose I have an Orders table in my database and a corresponding model class
If I have a Customers table linked to an Orders table, and I want
Lets say I have a Customers table and an Orders table with a one-to-many
I hope someone can help me out. I have a table that logs our
I have a table called orders this table contains all the information we need.

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.