Possible Duplicate:
sql query to sum the data
I have following table structure
TradeId TableName PricingSecurityID Quantity Price
2008 Fireball.dbo.Bond 506 50 100.0000
2009 Fireball.dbo.Bond 506 50 100.2500
2010 Fireball.dbo.Bond 588 50 100.7500
2338 Fireball.dbo.Bond 588 100 102.5000
I need to take a sum of Quantity
of matching or we can say group by particular PricingSecurityID
like for PricingSecurityID=506
I should get quantity=100
and for PricingSecurityID=588
I should get quantity=150
How can I write this SQL query?
I did try with simple group by statement but as i'm also selecting tradeid i'm getting error : Column 'TradeId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
SELECT PricingSecurityID, SUM(ISNULL(Quantity,0))
FROM Table
GROUP BY PricingSecurityId;
select PricingSecurityID, sum(quantity)
from Fireball.dbo.Bond
group by PricingSecurityID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With