问题
Hi I have the following table:
Doc | code | Qty | Next
5211386 | 91992 | 1 | 52183
5211386 | 91992 | 1 | 52182
I trying to figure out a way to group the records by the first two colums, sum the third and concat the last column to obtain something like:
Doc | code | Qty | Next
5211386 | 91992 | 2 | 52183-52182
Any help?
回答1:
Sounds like you're looking for a group_concat like function found in MySQL. Check out Allen Browne's solution
SELECT Doc, code, Sum(Qty), ConcatRelated("[Next]","TableName",,,"-") as [Next]
FROM TableName
GROUP BY Doc, code
来源:https://stackoverflow.com/questions/11232153/sql-query-to-group-by-and-concat-rows