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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:18:07+00:00 2026-06-02T20:18:07+00:00

I am trying to teach myself more about SQL at the moment and am

  • 0

I am trying to teach myself more about SQL at the moment and am currently trying to carry out some simple sales reporting using SUM, COUNT, AVG and GROUP BY functions within a SQL Server 2008 database. I have managed to get the total, count and average of each group by row.

How do I get the grand total of all the group by rows?

SQL so far:

SELECT 
    SUM(dbo.tbl_orderitems.mon_orditems_pprice) AS prodTotal,
    AVG(dbo.tbl_orderitems.mon_orditems_pprice) AS avgPrice,
    count(dbo.tbl_orderitems.uid_orditems_prodid) AS prodQty,
    dbo.tbl_orderitems.txt_orditems_pname
FROM 
    dbo.tbl_orderitems
INNER JOIN 
    dbo.tbl_orders 
    ON (dbo.tbl_orderitems.uid_orditems_orderid = dbo.tbl_orders.uid_orders)
WHERE 
    dbo.tbl_orders.uid_order_webid = 
       <cfqueryparam cfsqltype="cf_sql_integer" value="#session.webid#">
    AND dbo.tbl_orders.txt_order_status = 
       <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.sale_status#">
GROUP BY
    dbo.tbl_orderitems.txt_orditems_pname
Product                           Qty      Gross        Avg  

Westbury Climbing Frame           17       8,023.00     471.94
Sandpoint Deluxe Climbing Frame   34       36,146.00    1,063.12
Roseberry Climbing Frame          9        7,441.00     826.78
Ridgeview Texas Climbing Frame    10       6,990.00     699
Selwood Picnic Table              9        489.92       54.44

I need the Totals of qty column and gross column

Many thanks

Jason

  • 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-02T20:18:08+00:00Added an answer on June 2, 2026 at 8:18 pm

    You are looking for the ROLLUP operator which would add a grand total row at the end of the result set. If you are looking for more complex aggregate totals use ROLLUP or CUBE with the GROUP BY clause, such as the link provided by @MartinSmith or Aggregation WITH ROLLUP

    SELECT 
        SUM(dbo.tbl_orderitems.mon_orditems_pprice) AS prodTotal,
        AVG(dbo.tbl_orderitems.mon_orditems_pprice) AS avgPrice,
        count(dbo.tbl_orderitems.uid_orditems_prodid) AS prodQty,
        dbo.tbl_orderitems.txt_orditems_pname
    FROM 
        dbo.tbl_orderitems
    INNER JOIN 
        dbo.tbl_orders ON (dbo.tbl_orderitems.uid_orditems_orderid = dbo.tbl_orders.uid_orders)
    WHERE 
        dbo.tbl_orders.uid_order_webid = <cfqueryparam cfsqltype="cf_sql_integer" value="#session.webid#">
        AND dbo.tbl_orders.txt_order_status = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.sale_status#">
    GROUP BY
        dbo.tbl_orderitems.txt_orditems_pname
    WITH ROLLUP
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to teach myself more about javascript, and I find myself stumbling
I'm trying to teach myself some C++ and as an initial project, I want
I'm trying to teach myself C++, and I'm going through a basic exercise about
I'm trying to build a simple product backlog application to teach myself Rails. For
I am trying to teach myself LINQ to SQL and have decided to do
I'm trying to teach myself python using Google's AppEngine , and I can't get
I'm trying to teach myself about OOP in C#, but I have a question
I'm currently trying to teach myself Objective-C and was playing around with an exercise
I'm trying to teach-myself how to serialize/deserialize to/from XML using the attribute-based serializer. I've
I'm trying to teach myself OpenGL using pyopengl and I'm struck on trying to

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.