Я хочу просто вернуть одну строку данных с суммой данных, а также сгруппировать по идентификатору элемента производственного плана, в идеале, мне нужна строка, показывающая мне это поле и значение суммы qty, поэтому оно должно иметь значение
ProductionPlanItemId QtyCompleted
5865406 3
/****** Script for SelectTopNRows command from SSMS ******/
SELECT [CompletedPrintedId]
,[UserName]
,[ProductionPlanId]
,[QtyCompleted]
,[SubAssembledQty]
,[QtyRequired]
,[ProductionPlanItemID]
,[SOPOrderReturnLineId]
FROM [CompletedPrinted]
where DocumentNo='0000027084' and ProductionPlanItemID='5865406'
GROUP BY
[ProductionPlanItemID]
,[UserName]
,[ProductionPlanId]
,[QtyCompleted]
,[SubAssembledQty]
,[QtyRequired]
, [CompletedPrintedId]
,[SOPOrderReturnLineId]
Схема Colum:
CREATE TABLE [dbo].[CompletedPrinted](
[CompletedPrintedId] [bigint] NOT NULL,
[UserName] [nvarchar](66) NOT NULL DEFAULT (''),
[StartDateTIme] [datetime] NULL,
[EndDateTime] [datetime] NULL,
[ProductionPlanId] [bigint] NOT NULL DEFAULT ((0)),
[SopLineItemId] [nvarchar](64) NOT NULL DEFAULT (''),
[Detail] [nvarchar](1002) NOT NULL DEFAULT (''),
[isActive] [bit] NOT NULL DEFAULT ((0)),
[DocumentNo] [nvarchar](102) NOT NULL DEFAULT (''),
[StockCode] [nvarchar](32) NOT NULL DEFAULT (''),
[StockDescription] [text] NOT NULL DEFAULT (''),
[QtyCompleted] [bigint] NOT NULL DEFAULT ((0)),
[SubAssembledQty] [bigint] NOT NULL DEFAULT ((0)),
[QtyRequired] [bigint] NOT NULL DEFAULT ((0)),
[ProductionPlanItemID] [bigint] NOT NULL DEFAULT ((0)),
[SOPOrderReturnLineId] [bigint] NOT NULL DEFAULT ((0))
)
Я создал скрипту sql ниже с примерами данных.
http://sqlfiddle.com/#!18/8927c/2

Редактировать 2 Извините, я должен был заявить, что мне нужны другие столбцы.