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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:57:48+00:00 2026-05-11T16:57:48+00:00

[ edit ] For the record, here’s the problem portion of the query, which

  • 0

[ edit ]

For the record, here’s the problem portion of the query, which is now working:

SELECT 
 m.groupNum, 
 t.ea,
 ( t.ea - ( t.ea * m.margin )) AS estCost,
 (( t.ea - ( t.ea * m.margin )) * t.quantity ) AS salesSub,
 ((( t.ea - ( t.ea * m.margin )) * t.quantity ) / 
   (
    SELECT SUM(( t2.ea - ( t2.ea * m.margin )) * t2.quantity )
    FROM temp as t2
    INNER JOIN masters as m2 
    ON t2.mod = m2.mod
    WHERE m2.groupNum = m.groupNum
    )
  ) AS salesPercent
etc...

[ end edit ]

I think I need a query that can recursively update itself based on the total of a column’s values after inserting values on all the rest of the records for a given (groupNum) range.

I already have the estCost and salesSub fields. Now I need to do calculations on the salesPercent field, which involves knowing the total amount of all salesSub records in a given set (groupNum).

salesPercent = 
  ( salesSub / [the sum total of all salesSub amounts for each groupNum] )

(snip)

SELECT 
 m.id, 
 t.priceEach,
 ( t.priceEach - ( t.priceEach * m.margin )) AS estCost,
 (( t.priceEach - ( t.priceEach * m.margin )) * t.quantity ) AS salesSub
 -- is it possible to perform calculation on salesPercent here?
INTO output

FROM financeMasters AS m
INNER JOIN temp AS t .......

(end snip)

I have this…

------
output
---------------------------------------------------------------
id | groupNum | priceEach | estCost | salesSub | salesPercent |
---------------------------------------------------------------
1  | apple    | 150.00    |  90.00  | 90.00    |   
2  | apple    | 100.00    |  60.00  | 60.00    |   
3  | apple    |  50.00    |  30.00  | 30.00    |   

but how can I calculate salesPercent on the salesSub total (in this case 180.00) before knowing the total?

  • 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-11T16:57:48+00:00Added an answer on May 11, 2026 at 4:57 pm

    You’ll probably have to use a subselect to do the math on each row, there’s no way to “go back” and change previous rows.

    Something like this:

    SELECT 
     m.id, 
     t.priceEach,
     ( t.priceEach - ( t.priceEach * m.margin )) AS estCost,
     (( t.priceEach - ( t.priceEach * m.margin )) * t.quantity ) AS salesSub,
     ((( t.priceEach - ( t.priceEach * m.margin )) * t.quantity )
         / (SELECT SUM(( t2.priceEach - ( t2.priceEach * m.margin )) * t2.quantity )
            FROM financeMasters AS m2
                INNER JOIN temp AS t2 .....
            WHERE m2.groupNum = m.groupNum))
         AS salesPercent
    INTO output
    
    FROM financeMasters AS m
    INNER JOIN temp AS t .......
    

    Yes, it’s pretty ugly. I had to leave out some details due to not knowing how you were doing the join, and also I’m not sure which table that groupNum is coming from, you didn’t show that anywhere.

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

Sidebar

Ask A Question

Stats

  • Questions 189k
  • Answers 189k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nothing special, just declare a cursor over the select from… May 12, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer */* means that the user-agent accepts all formats and doesn't… May 12, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer This is one of those that really can go either… May 12, 2026 at 5:50 pm

Related Questions

[ edit ] For the record, here's the problem portion of the query, which
I'm writing some Javascript to resize the large image to fit into the user's
There is a similar question going around, but it just got the same old
I am new to threads and in need of help. I have a data
Please note the Edit below for a lot more information, and a possible solution

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.