# How to make sql query the average value of a tag in the last hour

**URL:** <https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009>\
**Category:** Ignition\
**Created:** [June 25, 2020, 6:08am UTC](https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009 "2020-06-25T06:08:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oleh](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@Oleh](https://forum.inductiveautomation.com/u/Oleh)\
**Post date:** [June 25, 2020, 6:08am UTC](https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009/1 "2020-06-25T06:08:13Z")

</div>

A have historical tag with address [default]TESTSTARTSTOP/Hours/Active power .How to make sql query the average value of this tag in the last hour?

---

<div class="post-metadata">

**Author:** ![pascal](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pascal](https://forum.inductiveautomation.com/u/pascal)\
**Post date:** [June 25, 2020, 7:22am UTC](https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009/2 "2020-06-25T07:22:14Z")

</div>

Hi,

How would you like to query your tag (with a property binding ? in a chart ? in a table ?)

One thing for sure is that you can do this using script.  
I would suggest you to check out this part of the user manual :  
[https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagHistory)

Why not using a transaction group to store your tag ?  
This way you can have control on the table name, the column where your tag will be stored and it will be easier to use complex SQL queries .

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 25, 2020, 7:46am UTC](https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009/3 "2020-06-25T07:46:42Z")

</div>

I think the queryTagCalculations function would be more appropriate:  
[https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagCalculations](https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagCalculations)

---

<div class="post-metadata">

**Author:** ![Ivan\_H](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ivan_h/32/28186_2.png) [@Ivan\_H](https://forum.inductiveautomation.com/u/Ivan_H)\
**Post date:** [December 14, 2021, 5:33pm UTC](https://forum.inductiveautomation.com/t/how-to-make-sql-query-the-average-value-of-a-tag-in-the-last-hour/36009/4 "2021-12-14T17:33:15Z")

</div>

Hi @nminchin, until this point i was trying to query manually from the Historian DB. This is the way, thank you very much.
