I have a query with the following code:
SELECT TOP (100) PERCENT machine, SUM(CASE WHEN lunch = 1 THEN (runtime) END) AS lunch_time, SUM(CASE WHEN paperwrk = 1 THEN (runtime) END)
AS paper_work, SUM(CASE WHEN stpbar = 0 AND lunch = 0 AND paperwrk = 0 THEN (runtime) END) AS idle_time, SUM(runtime) AS totaltime, shift,
GROUP BY machine, shift, jobtask
ORDER BY machine
What I am trying to add in is the T_STAMP from Prodtrack table. But when I add it in it wants to make it part of the GROUP BY statement as well and it messes up the output from the query. I have tried not having in the GROUP BY but when I do this, it comes up with the error about not being aggrigate or in group by. I have tried without success MIN and MAX but they dont seem to pick up the correct information. Is there a command I am not familiar with that would allow me to do as I require?
All I want it to do is add in the value from the T_STAMP column at the end of the data provided by the GROUP BY statement. Hopefully this is clear.
Thanks and have a great day.