# Displaying Totalized values from database based on Identifier and selected time range for report

**URL:** <https://forum.inductiveautomation.com/t/displaying-totalized-values-from-database-based-on-identifier-and-selected-time-range-for-report/89125>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [April 19, 2024, 4:10pm UTC](https://forum.inductiveautomation.com/t/displaying-totalized-values-from-database-based-on-identifier-and-selected-time-range-for-report/89125 "2024-04-19T16:10:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Skoog](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kyle\_Skoog](https://forum.inductiveautomation.com/u/Kyle_Skoog)\
**Post date:** [April 19, 2024, 4:10pm UTC](https://forum.inductiveautomation.com/t/displaying-totalized-values-from-database-based-on-identifier-and-selected-time-range-for-report/89125/1 "2024-04-19T16:10:13Z")

</div>

I am creating a report that is displaying the total value of ingredients added within a selected time frame for separate tanks. I am currently storing all tank ingredient data in the same table and have separate queries filtering the values based on the tank identifier. Doing it this way, I have to create separate tables with the different data source, and the design is sloppy. This works, but I wonder if there is a way to use only one table, or alternatives. Thanks.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/def8fa1c289cb9809dd23ec1375ce8e7284bdc0d.jpeg)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c5dc65f94884e4c59523f10bc0e5ff2787e5988a.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/0/a07eb7a53885fc252192a9c4bdba7b488cbab164.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/95b0634e21644377cc3192d319dbc3f4279078a9.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 19, 2024, 4:34pm UTC](https://forum.inductiveautomation.com/t/displaying-totalized-values-from-database-based-on-identifier-and-selected-time-range-for-report/89125/2 "2024-04-19T16:34:26Z")

</div>

If you looking for a report of the form,

| Tank | Water | Salt | SeaSalt | Sugar | Passes | Fails |
| --- | --- | --- | --- | --- | --- | --- |
| Tank 1 | 60 | 60 | 60 | 60 | 3 | 1 |
| Tank 2 | 60 | 60 | 60 | 60 | 4 | 0 |
| Tank 3 | 60 | 60 | 60 | 60 | 3 | 1 |

then your query will be of the form,

```python
SELECT 
	Tank, SUM(Water) AS Water, SUM(Salt) AS Salt, SUM(SeaSalt) AS SeaSalt, SUM(Sugar) AS Sugar, 
    SUM(Pass) AS Passes, COUNT(Pass) - SUM(Pass) AS Fails
FROM Brine_Reports
WHERE t_stamp BETWEEN '2024-04-19 08:00:00' AND '2024-04-19 20:00:00'
GROUP BY Tank

```

Try it out at SQL Fiddle.

> **[FREE AI-Enhanced Online MySQL Compiler - For learning & practice](https://sqlfiddle.com/mysql/online-compiler?id=f5744d57-fbbc-4999-8893-ec230f29e5a0)**
>
> Explore our free online MySQL editor to practice and execute SQL. AI-enhanced to chat, explain, and generate code. Start coding smarter today!

---

<div class="post-metadata">

**Author:** ![Kyle\_Skoog](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kyle\_Skoog](https://forum.inductiveautomation.com/u/Kyle_Skoog)\
**Post date:** [April 19, 2024, 6:53pm UTC](https://forum.inductiveautomation.com/t/displaying-totalized-values-from-database-based-on-identifier-and-selected-time-range-for-report/89125/3 "2024-04-19T18:53:55Z")

</div>

Thanks, this is what I'm looking for.
