> For the complete documentation index, see [llms.txt](https://query.docs.doyto.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://query.docs.doyto.win/object-concepts/view-object/group-by.md).

# Group By Mapping

For the `GROUP BY` clause, grouping fields typically also need to appear in the returned columns. This can be achieved by adding an annotation to the field in the view class to declare it as a grouping column, which will then be appended to the `GROUP BY` clause during mapping.

**Example**

When defining a view object, add the `@GroupBy` annotation to the fields used for grouping:

```java
@GroupBy
private int returnFlag;

@GroupBy
private int lineStatus;
```

Fields marked with the `@GroupBy` annotation are mapped as:

```sql
SELECT return_flag, line_status, ... FROM ...
GROUP BY return_flag, line_status ...
```
