重新排列表格(仅汇总某些行)

时间:2019-02-22 03:39:41

标签: sql-server

我有下表: enter image description here

因此,每当我有共同的“ J No”时,我想执行以下计算:

仅取“ Setup Start”中的第一个值,并将其与“ Run Start”和“ Run End”中的最后两个值合并,并删除它们之间的任何记录。

这是我的查询代码:

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

我该如何修改此查询以提供上面列出的所需输出?

1 个答案:

答案 0 :(得分:1)

松鼠提到的类似东西

SELECT [J No]
    ,MIN([SetupStart]) AS [SetupStart]
    ,MAX(UpTimeStart) AS UpTimeStart
    ,MAX(UpTimeEnd) AS UpTimeEnd
FROM [Initial].[dbo].[vWGetProductionInfo]
GROUP BY [J No]