Hi, I currently have the query as below. However I want to work out how many units I have sold. To do this I need to multiply the od.ingredientid with od.quantity on a row per row basis, then the total of that is the amount of units sold. Is this possible all within SQL? select od.fkingredientid, od.quantity from dorderdetails od, dordergroups og where og.pkordergroupid = od.fkordergroupid and od.fkingredientid = 391 and og.deleted = 0 Code (markup): Thanks in advance.
I don't really understand your database structure, but you can generally do something like this: SELECT (ingredient*quantity) AS totsold FROM....WHERE You do the math you want, enclose it in parenthesis, then ad 'AS' and then give it a name. I don't know if this will get you all the way where you want to go, because I suspect you need to summarize that quantity after you calculate it.
You should use group by with roll up for the total amount. It's better if you provide table structure and required fields for the resultset