# Group sql data and sum total

**URL:** <https://forum.inductiveautomation.com/t/group-sql-data-and-sum-total/98782>\
**Category:** Ignition\
**Created:** [November 19, 2024, 2:35pm UTC](https://forum.inductiveautomation.com/t/group-sql-data-and-sum-total/98782 "2024-11-19T14:35:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![I\_Zayah\_Griffin](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@I\_Zayah\_Griffin](https://forum.inductiveautomation.com/u/I_Zayah_Griffin)\
**Post date:** [November 19, 2024, 2:35pm UTC](https://forum.inductiveautomation.com/t/group-sql-data-and-sum-total/98782/1 "2024-11-19T14:35:35Z")

</div>

I need help is there an easy way to group by class and add the total\_time.  
This is my current expression to get the resulting SQL table below

```python
leftJoin(
  {value},
  {[default]New Tag},
  it()['Reason_id'],
  it()['Reason_id']
)

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8af68158d3f47346849c42fcd095a47670047712.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 19, 2024, 6:27pm UTC](https://forum.inductiveautomation.com/t/group-sql-data-and-sum-total/98782/3 "2024-11-19T18:27:41Z")

</div>

I made your given expression a tag, then created another expression to do the grouping. Feel free to combine them into one expression if you'd like.

I was able to write this from an [example](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934/19) in the thread that Phil linked to in your [original thread](https://forum.inductiveautomation.com/t/join-2-tables-from-different-databases/98734).

```python
forEach(
	groupBy({[default]Testing/Dataset},it()['classification']),
	asMap(
		'classification',it()[0],
		'TotalMinutes', sum(it()[1],'TotalMinutes')
	) 
)

```

---

<div class="post-metadata">

**Author:** ![I\_Zayah\_Griffin](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@I\_Zayah\_Griffin](https://forum.inductiveautomation.com/u/I_Zayah_Griffin)\
**Post date:** [November 19, 2024, 8:31pm UTC](https://forum.inductiveautomation.com/t/group-sql-data-and-sum-total/98782/4 "2024-11-19T20:31:43Z")

</div>

Thank you so much, that worked way simpler than the way I was trying to go about it
