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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:39:59+00:00 2026-06-15T01:39:59+00:00

I have a query; select ProductID, name, (unitPrice*quantity) As ‘Stock Equity’ from tproduct group

  • 0

I have a query;

select ProductID,  name, (unitPrice*quantity) As 'Stock Equity'
from tproduct
group by productID with rollup
;

I wish for this to return a set of rows with the last being a calculation of the Total, instead its repeating the last result?

can anyone tell me why and how to overcome this please?

this is the query result at the moment;

ProductID    Name           Stock Equity
1            cannon 600 D   3360
2            cannon 550 D   1000
3            cannon 500 D   750
4            cannon 5D      5000
5            cannon 650 D   9000
6            Nikon D5100    1000
7            Nikon D3200    420
8            Nikon D7000    2700
9            Nikon D800     6030
10           Nikon D90      4770
null         Nikon D90      4770
  • 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-15T01:40:00+00:00Added an answer on June 15, 2026 at 1:40 am

    You can use UNION ALL:

    select ProductID,  name, (unitPrice*quantity) As 'Stock Equity'
    from tproduct
    union all
    select 'total', 'total', sum(unitPrice*quantity)
    from tproduct
    

    See SQL Fiddle with Demo

    Or you can use something like this:

    select case when ProductID is null then 'total' else ProductId end Productid,  
      case when ProductID is null then 'total' else name end name, 
      sum(unitPrice*quantity) As 'Stock Equity'
    from tproduct
    group by ProductID with rollup
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

I have a query: select substr(name,7,50) as location, points,sum(if (p1=r1,10,-10))as total from dq.data group
I have this query: SELECT bp.product_id,bs.step_number, p.price, pd.name as product_name FROM builder_product bp JOIN
I have an Rails ActiveRecord group query: a = Product.select(date(date) as date, count(id) as
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: Select (Country.Name + ', ' + City.Name) as Location ...
I have the below query: SELECT p.id as prod_id, * FROM products AS p
If I have the following full text search query: SELECT * FROM dbo.Product INNER
I have a working query as SELECT p.id, p.name AS ProductName, count(DISTINcT s.salesid) as
I have a query that looks like this: SELECT p.prodname, p.prodcode, o.vovalue, p.productid, i.imageprodid,
I have this query where I can search the TABLE_GLOBAL_PRODUCTS $catglobal_sql = select p.*,

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.