如何在 Scala 集合中使用多列进行分组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31468343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 07:22:09  来源:igfitidea点击:

How to groupBy using multiple columns in scala collections

scalacollections

提问by krisp

records.groupBy(_.column1)

What if I want to include more columns like if I want to group by column1, column2 and column3?

如果我想包含更多的列,比如我想按 column1、column2 和 column3 分组怎么办?

Any hints?

任何提示?

回答by Ren

Try

尝试

records.groupBy(record => (record.column1, record.column2, record.column3))

This will group by a tuple composed of those 3 columns.

这将按由这 3 列组成的元组进行分组。