sql - SUM(a*b) not working -
Wo_parts and part2vendor . I am trying to multiply 2 table column row dots together, i.e. wo_parts is a field called qty and a field in part2vendor Which is called cost . These 2 include wo_parts.pn and part2vendor.pn . I have created a query like this: part2vendor INNER as total_score as wo_parts ON (wo_parts.pn =)
$ scoreCostQuery = "SELECT SUM (part2vendor.cost * wo_parts.qty) Part2vendor.pn) WHERE WORKER = $ WORKER ";
But if I add the cost of parts multiplied by the supplied qaantsities, then it adds a different number than what the script is doing. Help .... I'm new to this but if someone can show me in SQL then I can modify it for postgres. Thanks
Without seeing the example data, we have no way to know that you query Why are yoga coming out in a different way when you do mathematics by hand it can be a bad insert, so you are getting more / less records than expected. It is also possible that your calculation is closed. Select an example with the smallest number of associated records & amp; Compare.
My suggestion is to add the query to GROUP BY
:
SELECT SUM (p.cost * wp.qty) to the total_core from FROM Part2vendor p JOIN wo_parts wp on wp.pn = p.pn where workorder = $ was in workorder group functionality by
FYI: MySQL GROUP BY
, while another DB Used - it is a source of many questions "Why does it work in MySQL when it does not work on DB x ...".
To check that your quantities are correct:
SELECT wp.qty, pOost to WO_PARTS wp PART2VENDOR p on PPN = Wp.pn where p.workorder = $ workorder
Check that the numbers are correct for a given order.