# group by in query

**URL:** <https://www.dynamicsuser.net/t/group-by-in-query/15023>\
**Category:** Developer Forum\
**Created:** [February 6, 2004, 12:18pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023 "2004-02-06T12:18:52Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalliet](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@kalliet](https://www.dynamicsuser.net/u/kalliet)\
**Post date:** [February 6, 2004, 12:18pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/1 "2004-02-06T12:18:52Z")

</div>

Hallo, How do I force a “group by” in the visual query? I know that “sort by” is in the Sorting and “where” is in the Range, but how do I get a group by in the query ? thx, Kathleen

---

<div class="post-metadata">

**Author:** ![krish\_roy](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@krish\_roy](https://www.dynamicsuser.net/u/krish_roy)\
**Post date:** [February 6, 2004, 1:10pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/2 "2004-02-06T13:10:12Z")

</div>

You can try like this: TableName var; ; select var group by (FieldName) //Field of the Table where (condition); It should work.

---

<div class="post-metadata">

**Author:** ![kalliet](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@kalliet](https://www.dynamicsuser.net/u/kalliet)\
**Post date:** [February 6, 2004, 1:14pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/3 "2004-02-06T13:14:29Z")

</div>

I would like to know how to do that with the AOT (the drag and drop environment) kathleen

---

<div class="post-metadata">

**Author:** ![danang\_ismu](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@danang\_ismu](https://www.dynamicsuser.net/u/danang_ismu)\
**Post date:** [February 7, 2004, 5:52am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/4 "2004-02-07T05:52:08Z")

</div>

hi Kalliet, in the sorting when you add the field which the query will be sort … you can see in the property … that is property name autoheader and autosum … i think that use for groupby hope it’s help 🙂 regards, Danang Ismu

---

<div class="post-metadata">

**Author:** ![pkarlss](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@pkarlss](https://www.dynamicsuser.net/u/pkarlss)\
**Post date:** [February 9, 2004, 8:47am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/5 "2004-02-09T08:47:30Z")

</div>

Hello, In Querys it seems to be no property for Group By. On the other hand, when you look at Querys in reports. Then you find the property AutoSum used for Group By in reports (Report → Data Source → CustTrans → Sorting → AccountNumber). /Peter Karlsson

---

<div class="post-metadata">

**Author:** ![danang\_ismu](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@danang\_ismu](https://www.dynamicsuser.net/u/danang_ismu)\
**Post date:** [February 9, 2004, 9:51am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/6 "2004-02-09T09:51:25Z")

</div>

hallo Peter, thx … that what i mean … querys in report … sorry for my mistake 😛 regards, Danang Ismu

---

<div class="post-metadata">

**Author:** ![kalliet](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@kalliet](https://www.dynamicsuser.net/u/kalliet)\
**Post date:** [February 10, 2004, 8:46am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/7 "2004-02-10T08:46:03Z")

</div>

Hello, My problem is as followed: I would like to give an overview of the hours worked by the employees (with a total per day) → how can I do that in the sorting of the query i.e. how do I autosumize the amount of hours per transdate? Or do I have to keep track of it manually in the code? thx, Kathleen Alliët

---

<div class="post-metadata">

**Author:** ![pkarlss](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@pkarlss](https://www.dynamicsuser.net/u/pkarlss)\
**Post date:** [February 12, 2004, 8:34am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/8 "2004-02-12T08:34:39Z")

</div>

Hi Kathleen, If you use a report, then it’s no problem to get a total per date. Use the datefield as first sortingfield in the query (query on the report), and set the property AutoSum on the sortingfield to Yes. Oh, i hope there is a datefield in your table. If not, then i think you have to use code to sum the transactions. /Peter Karlsson

---

<div class="post-metadata">

**Author:** ![pkarlss](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@pkarlss](https://www.dynamicsuser.net/u/pkarlss)\
**Post date:** [February 19, 2004, 2:07pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/9 "2004-02-19T14:07:39Z")

</div>

Hi again, I feel that I must correct my answer [:I]. You **CAN** group transactions in “standard” querys. Above i said thay you only can group transactions when you use querys in reports. But i just found the way to do it. 1. As sortingfield you use the field you want to group by. 2. The property OrderMode (Data Source → Table) is set to Group by. All done ! In x++ it can look someting like this. _queryds.addSortField(fieldnum(CustTrans,AccountNum)); queryds.orderMode(1);_ /Peter Karlsson

---

<div class="post-metadata">

**Author:** ![krish\_roy](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@krish\_roy](https://www.dynamicsuser.net/u/krish_roy)\
**Post date:** [February 20, 2004, 4:56am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/10 "2004-02-20T04:56:44Z")

</div>

Hi Peter, What I feel, Kathleen wants the ‘Group By’ to be done in MorphX Environment. Using X++ coding, it can be managed in multiple ways … not a big issue. Kathleen did you find any way out? Thanks.

---

<div class="post-metadata">

**Author:** ![tj\_jayson](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tj\_jayson](https://www.dynamicsuser.net/u/tj_jayson)\
**Post date:** [February 21, 2004, 4:31am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/11 "2004-02-21T04:31:54Z")

</div>

If want to show in a form for the user . Will it be good idea of adding a new index in the table and use that index in the data souurce of the form.So you will get group by automaticaly based on the index order.

---

<div class="post-metadata">

**Author:** ![hua](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@hua](https://www.dynamicsuser.net/u/hua)\
**Post date:** [February 23, 2004, 3:45am UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/12 "2004-02-23T03:45:16Z")

</div>

Hi, kalliet It is very easy, you can reference the report tutorial\_SumPerSubFieldDate, and you can find it in AOT/Report. wish this help you.

---

<div class="post-metadata">

**Author:** ![massoud](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@massoud](https://www.dynamicsuser.net/u/massoud)\
**Post date:** [April 27, 2005, 8:42pm UTC](https://www.dynamicsuser.net/t/group-by-in-query/15023/13 "2005-04-27T20:42:38Z")

</div>

look at this code: (OrderMode) q = new query(salesTable\_DS.queryRun().query()); q.dataSourceTable(tablenum(salesLine)).addSelectionField(fieldnum(salesLine, lineamount), SelectionField::Sum); q.dataSourceTable(tablenum(salesLine)).addSortField(fieldnum(salesline, salesId)); q.dataSourceTable(tablenum(salesLine)).addSortField(fieldnum(salesline, dataAreaId)); q.dataSourceTable(tablenum(salesLine)).orderMode(OrderMode::GroupBy); queryRun = new queryRun(q);
