Link to home
Start Free TrialLog in
Avatar of Southern_Gentleman
Southern_GentlemanFlag for United States of America

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.
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

can you explain more.. not clear when to take the SUM sales amount .
Avatar of Éric Moreau
Would it be:

select sum(saleamount)
from TableName
where quantity = (select top 1 Quantity from TableName where type = 'J')

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India 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