唯一性
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
在聚合数据时,一个有用的做法是在聚合之前首先删除重复的输入。一些聚合函数支持为此目的的 DISTINCT
关键字。例如,我们可以查询
SELECT count(AUTHOR_ID), count(DISTINCT AUTHOR_ID), group_concat(AUTHOR_ID), group_concat(DISTINCT AUTHOR_ID) FROM BOOK
create.select( count(BOOK.AUTHOR_ID), countDistinct(BOOK.AUTHOR_ID), groupConcat(BOOK.AUTHOR_ID), groupConcatDistinct(BOOK.AUTHOR_ID)) .from(BOOK).fetch();
产生
+-------+----------------+--------------+-----------------------+ | count | count_distinct | group_concat | group_concat_distinct | +-------+----------------+--------------+-----------------------+ | 4 | 2 | 1, 1, 2, 2 | 1, 2 | +-------+----------------+--------------+-----------------------+
如果 DISTINCT
可通过 jOOQ API 获得,它总是附加到聚合函数名称,例如 count()
和 countDistinct()
。sum()
和 sumDistinct()
等。
反馈
您对此页面有任何反馈吗? 我们很乐意听到您的意见!