Southern_Gentleman
asked on
sql value based on a couple variables
quantity product desction type saleamount
315 xyz product1 100
315 mnd product2 200
315 dnd product3 563
14 dioa product4 456
315 xxx product5 J 144
1 ddd product6 226
315 dqi product7 144
So i'm trying to sum the saleamount product based on the following
take the quantity of the row where type is 'J' (So this would be 315) then SUM sales amount column if quantity has 315. so the value would be 1151
this would be dynamic since this is just an example.
315 xyz product1 100
315 mnd product2 200
315 dnd product3 563
14 dioa product4 456
315 xxx product5 J 144
1 ddd product6 226
315 dqi product7 144
So i'm trying to sum the saleamount product based on the following
take the quantity of the row where type is 'J' (So this would be 315) then SUM sales amount column if quantity has 315. so the value would be 1151
this would be dynamic since this is just an example.
can you explain more.. not clear when to take the SUM sales amount .
Would it be:
select sum(saleamount)
from TableName
where quantity = (select top 1 Quantity from TableName where type = 'J')
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.