Link to home
Start Free TrialLog in
Avatar of steven
stevenFlag for United States of America

asked on

Sql Group by issues

I want the output per item sum by the qty ordered.  Group by i guess i don't unerstand.  I don't want to create a table and sum  from that.   Is there a way to do this?




            select      c.item,
                        i.description,
                        i.u_m,
                        i.stocked,
                        i.safety_stock_percent,
                        w.qty_reorder,
                        i.plan_code,
                        datepart(mm,c.due_date) AS 'Due_month',
                        sum(c.qty_ordered)
            from   coitem c
                  inner join item i on i.item = c.item
                  inner join itemwhse w on w.item = i.item
            where c.due_date between @sdate and @edate
            and  i.item = 'F2002331'
            GROUP BY datepart(mm,c.due_date),
                     (qty_shipped),
                        c.item,
                        i.description,
                        i.u_m,
                        i.stocked,
                        i.safety_stock_percent,
                        w.qty_reorder,
                        i.plan_code
            order by datepart(mm,c.due_date)
Avatar of Ryan McCauley
Ryan McCauley
Flag of United States of America image

I'm not sure exactly what result you want to see - you say "output per item sum by the qty ordered", but I'm not sure what that would look like. Are you trying to view all the order you have and see how many items have been ordered and shipped for each order? Or are you looking for something else?

Some more detail about what you're looking to see in the end result would be helpful here (including, if possible, an example of your source data and what you actual expect as the result).
ASKER CERTIFIED SOLUTION
Avatar of steven
steven
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
Avatar of steven

ASKER

I added a having clause and got the results i needed.  Thanks