SQLTeam.com | Weblogs | Forums

Re-Arrange Table (summarize only certain rows)

sql2012

#1

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:
SELECT
[LineNo]
,[J No]
,[FC]
,[SetupStart]
,[UpTimeStart]
,[UpTimeEnd]
,[Setup]
,[UpTime]
,[Targ Len]
,[Act Len]
,[R Up F]
,[R Dn F]
,[Scrap]
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?


#2

[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'
FROM[Initial].[dbo].[vWGetProductionInfo]
group by [J No]