分组依据和连接行的 SQL 查询 [英] SQL Query to Group By and Concat rows
本文介绍了分组依据和连接行的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下表:
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
有什么帮助吗?
推荐答案
听起来您正在寻找 MySQL 中类似 group_concat 的函数.查看 Allen Browne 的解决方案
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
这篇关于分组依据和连接行的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文