Link to home
Start Free TrialLog in
Avatar of Basicfarmer
BasicfarmerFlag for United States of America

asked on

Need assistance with SQL Query

I need a query to return the totals for the items of a project. The ProjectItems table has the following columns.

ID
ProjectID
Qty
Cost
List
Discount

So I need it to return Total Cost, List Price and Sell Price.

Total Cost would be the sum of (Qty * Cost) in each row
List Price would be the sum of (Qty * List) in each row
Sell Price would be the sum of ((1 - Discount) * (Qty * List)) in each row

User generated image
Avatar of Steve Wales
Steve Wales
Flag of United States of America image

This should do the job for you

select ID, ProjectID, Qty, Cost, List, Discount, Qty * Cost as TotalCost, Qty * List as ListPrice, ((1 - Discount) * (Qty * List)) as SellPrice
from ProjectItems

Open in new window

Avatar of Basicfarmer

ASKER

Yes, that will give me the Totals for each row, but what I need is the Sum of the rows based on those calculations.
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guys, I was stuck on the Group By. That is exactly what I needed.