SQLTeam.com | Weblogs | Forums

Re-Arrange Table (summarize only certain rows)



I have the following Table:

Thus, whenever I have common “J No”, I would like to perform the following calculations:

Take only the 1st value from “Set up Start” and combine it with the last two values from “Run Start” and “Run End” and delete any records in between them.

Here is my Query code:
,[J No]
,[Targ Len]
,[Act Len]
,[R Up F]
,[R Dn F]
FROM [Initial].[dbo].[vWGetProductionInfo]
ORDER BY SetupStart ASC, UpTimeEnd AS

How would I do modify this query to give me the desired output I have listed above?


[J No],
max([FC]) as 'FC',
max([SetupStart]) as 'SetupStart',
min([UpTimeStart]) as 'UpTimeStart',
min([UpTimeEnd]) as 'UpTimeEnd'
... etc...
max([R Dn F]) as R Dn F',
max([Scrap]) as 'Scrap'
group by [J No]