如何在Ballerina查询表达式中获取DISTINCT值?
在Ballerina查询表达式中获取DISTINCT值
当然可以通过Ballerina查询表达式获取唯一值,你只需要在select关键字前添加distinct关键字,就能自动过滤结果中的重复元素。修改后的代码如下:
string[]|error connectorProducts = from record {string product;} {product} in products distinct select product;
distinct关键字会对查询返回的结果做去重处理,最终connectorProducts数组里只会保留不重复的product字符串。如果后续遇到多字段去重的场景,还可以将目标字段组合成不可变的tuple或record后再使用distinct,不过针对你当前的单字段去重需求,上面的代码就完全够用。
内容的提问来源于stack exchange,提问作者shayanmalinda
相关产品推荐
相关产品推荐

