File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
main/java/org/mybatis/dynamic/sql/select
test/java/org/mybatis/dynamic/sql/select Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,12 @@ public SelectDSL<R> orderBy(SortSpecification...columns) {
216216 return selectDSL ;
217217 }
218218
219+ public GroupByFinisher groupBy (BasicColumn ...columns ) {
220+ groupByModel = GroupByModel .of (columns );
221+ selectDSL .addQueryExpression (buildModel ());
222+ return new GroupByFinisher ();
223+ }
224+
219225 @ Override
220226 public R build () {
221227 whereModel = buildWhereModel ();
Original file line number Diff line number Diff line change @@ -236,4 +236,28 @@ public void testNoWhere() {
236236 softly .assertThat (parameters .size ()).isEqualTo (0 );
237237 });
238238 }
239+
240+ @ Test
241+ public void testGroupBySingleColumn () {
242+ Date d = new Date ();
243+
244+ SelectStatementProvider selectStatement = select (column1 .as ("A_COLUMN1" ), column2 )
245+ .from (table , "a" )
246+ .where (column1 , isEqualTo (d ))
247+ .groupBy (column2 )
248+ .build ()
249+ .render (RenderingStrategy .MYBATIS3 );
250+
251+ SoftAssertions .assertSoftly (softly -> {
252+ String expectedFullStatement = "select a.column1 as A_COLUMN1, a.column2 "
253+ + "from foo a "
254+ + "where a.column1 = #{parameters.p1,jdbcType=DATE} "
255+ + "group by column2 " ;
256+
257+ softly .assertThat (selectStatement .getSelectStatement ()).isEqualTo (expectedFullStatement );
258+
259+ Map <String , Object > parameters = selectStatement .getParameters ();
260+ softly .assertThat (parameters .get ("p1" )).isEqualTo (d );
261+ });
262+ }
239263}
You can’t perform that action at this time.
0 commit comments