>>Is it possible to also get a count of all the orders in each state who's Amount sum falls into certain ranges?I'm not sure if by "Amount sum" you mean "amount" or "sum(amount)" but since you say "in each state" I will assume you mean the count of "Amount" in a certain range. Try this:declare @lowRange int ,@highRange intselect @lowRange = 10 ,@highRange = 20select State ,COUNT(distinct OrderNo) ,SUM(Amount) / Count(distinct OrderNo) AS Average ,sum(inRange) as CountInRangefrom ( select [Order No] ,ItemNo ,Amount ,State ,inRange = case when Amount between @lowRange and @highRange then 1 else 0 end FROM Orders ) aGROUP BY State
Be One with the OptimizerTG