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 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

Related Questions

edit: I should probably say how I am currently worked around the problem here.
I am trying to edit a record. I have the default route. When I
I have the following code [in doPost()] to edit existing record. It does not
I'm about to start a project that will record and edit audio files, and
EDIT: I have added Slug column to address performance issues on specific record selection.
I was wondering if its ok to edit the created_at value of a record
Edit: This question was written in 2008, which was like 3 internet ages ago.
i am trying to edit a mysql database record , there is seem to
Here is model column: title = Column(Unicode(100)) When I try to add a record
I allow users to view and edit a few fields of a database record

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.