SQL Query to Group By and Concat rows

余生长醉 提交于 2021-02-05 08:27:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!