我当前的 SQL 查询:
SELECT WorkOrderParts.PartQTY,
'$' + CONVERT(varchar(22), WorkOrderParts.PartCost, 1) AS PartCost,
'$' + CONVERT(varchar(22), WorkOrderParts.PartQTY * WorkOrderParts.PartCost, 1) AS PartsTotal,
tblParts.fldMfgPartNumber
FROM tblWorkorders
INNER JOIN WorkOrderParts ON tblWorkorders.ID = WorkOrderParts.WorkOrderId
INNER JOIN tblParts ON WorkOrderParts.PartId = tblParts.ID
WHERE (tblWorkorders.ProcessedDate BETWEEN '5/1/2012 12:00:00 AM'
AND '5/2/2012 12:00:00 AM')
GROUP BY tblWorkorders.ProcessedDate, WorkOrderParts.PartCost,
WorkOrderParts.PartQTY, tblParts.fldMfgPartNumber, tblWorkorders.ID
ORDER BY tblParts.fldMfgPartNumber
返回的数据:
PartQTY PartCost PartsTotal fldMfgPartNumber
------- -------- ---------- ----------------
1 $48.71 $48.71 1878042C91
1 $48.71 $48.71 1878042C91
1 $48.71 $48.71 1878042C91
1 $11.82 $11.82 1R1804
1 $11.82 $11.82 1R1804
1 $11.82 $11.82 1R1804
4 $255.39 $1,021.56 2697041
1 $8.94 $8.94 3719
如何修改我的 SQL 查询以返回以下结果:
PartQTY PartCost PartsTotal fldMfgPartNumber
------- -------- ---------- ----------------
3 $48.71 $146.13 1878042C91
3 $11.82 $35.46 1R1804
4 $255.39 $1,021.56 2697041
1 $8.94 $8.94 3719