I found that the distinct function in the Factory class only accepts one parameter
public static AggregateFunction<Integer> countDistinct(Field<?> field);
and there is no function like distinct(Field... fields)
I want to to express a SQL statement like this:
select c1, count(distinct c2,c3) from t1 group by c1;
PS: there is a non-dsl api: SelectQuery.setDistinct(true), but it will “distinct” all columns, which is not what I want.
That is interesting. To my knowledge, this should not be possible in SQL. The SQL:2008 standard specifies
There is no room for comma-separated argument lists, with or without the
DISTINCTset quantifier. This is implemented correctly in Oracle:Yet, MySQL seems to allow for this non-standard "convenient syntax":
(taken from http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_count).
To answer your question, this is currently not possible in jOOQ, although I filed #1728 for future support. Currently, you can work around this by writing your own multi-argument aggregate function support:
See the relevant Javadoc for the
Factory.field(String, Class<T>, QueryPart...)method for detailsThis is now implemented in jOOQ 2.6:
You can write
See the Javadoc for the
Factory.countDistinct(Field...)method, for details