Jump to content

Help with query - sum of several rows


aebstract

Recommended Posts

SELECT customfieldview.info, customfieldview.recordid, product.partid, sum(soitem.totalprice) AS totalprice, soitem.productid, product.id

FROM customfieldview
JOIN product ON customfieldview.recordid = product.partid
JOIN soitem ON soitem.productid = soitem.productid

WHERE customfieldview.info = 'Fabricated'


 

Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause)

 

and if I remove the quotes from fabricated I get:

 

Column unkownFABRICATEDAt line 7, column 30

 

What I'm trying to do is take every product that has a "customlistitem.name" = "Fabricated", get the product.partid (may result in 1-3 or so rows), use the id column from the product table to get a sum of soitem.totalprice for every product.id that was returned from "Fabricated". I'm needing the value of the total sum for all rows that match these requirements.

Any more info needed let me know, thanks.

Link to comment
https://forums.phpfreaks.com/topic/187618-help-with-query-sum-of-several-rows/
Share on other sites

Fixed this paragraph:

 

What I'm trying to do is take every product that has a "customfieldview.info" = "Fabricated", get the product.partid  that matches the customfieldview.recordid(may result in 1-3 or so rows), use the id column from the product table to get a sum of soitem.totalprice where soitem.productid = product.id, for every product.id that was returned from "Fabricated". I'm needing the value of the total sum for all rows that match these requirements.

Any more info needed let me know, thanks.

Okay, that's something I was unaware that I couldn't do, right now I have this:

 

SELECT customfieldview.info, customfieldview.recordid, product.partid, soitem.totalprice AS totalprice, soitem.productid, product.id

FROM customfieldview
JOIN product ON customfieldview.recordid = product.partid
JOIN soitem ON soitem.productid = product.id

WHERE customfieldview.info = 'Fabricated'

ORDER BY product.id

 

Which is displaying every product.id the correct amount of times, but the value (totalprice) is "null" for every row. Something to do with how it is joined?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.