group by的问题!
SELECT CustomerID, ItemNumber, ShippedQuantity
FROM dbo.FS_HistoryShipment
WHERE (OrderType = 'C') AND (IssueType = 'I') AND (UserID = 'C14') AND (Stockroom = 'FG') AND (CONVERT(NVARCHAR(10), TransactionDate, 120)
= CONVERT(NVARCHAR(10), GETDATE() - 1, 120))
SELECT CustomerID, ItemNumber, sum(ShippedQuantity) as qty
FROM dbo.FS_HistoryShipment
WHERE (OrderType = 'C') AND (IssueType = 'I') AND (UserID = 'C14') AND (Stockroom = 'FG') AND (CONVERT(NVARCHAR(10), TransactionDate, 120)
= CONVERT(NVARCHAR(10), GETDATE() - 1, 120))
GROUP BY CustomerID, ItemNumber
聚合时候,ItemNumber和CustomerID一样了。
但是其他的可以;搞不懂!SQL2005
------解决方案--------------------SELECT rtrim(CustomerID), rtrim(ItemNumber), sum(ShippedQuantity) as qty
FROM dbo.FS_HistoryShipment
WHERE (OrderType = 'C') AND (IssueType = 'I') AND (UserID = 'C14') AND (Stockroom = 'FG') AND (CONVERT(NVARCHAR(10), TransactionDate, 120)
= CONVERT(NVARCHAR(10), GETDATE() - 1, 120))
GROUP BY rtrim(CustomerID), rtrim(ItemNumber)
可能前后有空格,你这样试一下
------解决方案--------------------