Group by doesnt work. I need to add time for particular user. time is the 3rd column of result set posted below. first is the quantity
SELECT
sum(woitem.qtytarget) AS woitemtotal, sysuser.username as USERNAME, timeworked.info as timetaken
FROM mo
INNER JOIN moitem ON mo.id = moitem.moid
LEFT JOIN wo ON moitem.id = wo.moitemid
LEFT JOIN woitem ON wo.id = woitem.woid AND woitem.typeid = 10
LEFT JOIN SYSUSER ON mo.userid = sysuser.id
left join customdecimal timeworked on timeworked.recordid = mo.id
WHERE cast(wo.datestarted as date) = '10-21-2015'
group by sysuser.username
then please post the source data and the result you expect. Your original query neither groups by timeworked.info nor aggregates it. You must do one or the other
select distinct sysuser.username as WOUser, sum(timeworked.info) as timeworked, sum(woitem.qtytarget) AS woitemtotal
from po
inner join trackinginfo lot on lot.info = po.num and lot.tableid = -355941248
inner join woitem on lot.recordid = woitem.id
inner join wo on woitem.woid = wo.id AND woitem.typeid = 10
inner join part on woitem.partid = part.id
inner join product on product.partid = part.id
inner join moitem on wo.moitemid = moitem.id
inner join mo on moitem.moid = mo.id
left join sysuser on sysuser.id = wo.userid
left join customdecimal timeworked on timeworked.customfieldid = 15 and timeworked.recordid = mo.id
WHERE cast(wo.datestarted as date) = '2015-10-21'
group by sysuser.username , timeworked.info
order by sysuser.username