steven
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)
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added a having clause and got the results i needed. Thanks
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).