The precedence is not correct in this formula.
What I want to do is calculate a subtotal without the discount. Can someone tell me where I'm making my mistake?
((`p`.`tax_state` + `p`.`tax_fed`) / 100) *
((`p`.`price` * `op`.`quantity`) -
开发者_开发知识库 ((`p`.`price` * `op`.`quantity`) * `op`.`discount`))
Given that the tax rates are stored as percentages, but the discount is stored as a fraction (so much for consistency!), and noting that the backticks really aren't necessary and are very undesirable for readability, then...
(p.price * op.quantity) AS gross_price_exc_tax,
(p.price * op.quantity) * (1 + (p.tax_state + p.tax_fed) / 100)
AS gross_price_inc_tax,
(p.price * op.quantity) * (1 + (p.tax_state + p.tax_fed) / 100) *
(1 - op.discount) AS net_price_inc_tax,
...
These are pretty similar to what you wrote, so you need to demonstrate what you have as input data, and what you are getting as results, and you should be able to explain what you expected as a contrast to what you got. Is there any danger that MySQL is treating some part of the expression(s) as an integer when you expect it to be a floating point value?
You should also do as I did, and build up your set of expressions one piece at a time, analyzing the results each time. This can help you find problems quicker. For example, I could add:
(1 + (p.tax_state + p.tax_fed) / 100) AS tax_multiplier
If that showed up as 1 instead of 1.125 or whatever the correct fraction is, then I'd know to review that expression, probably adding decimal points to the two constants.
精彩评论