# Getting max run rate

**URL:** <https://forum.inductiveautomation.com/t/getting-max-run-rate/87217>\
**Category:** General Discussion\
**Created:** [March 12, 2024, 8:19pm UTC](https://forum.inductiveautomation.com/t/getting-max-run-rate/87217 "2024-03-12T20:19:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 20, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/getting-max-run-rate/87217/2 "2024-03-20T16:16:11Z")

</div>

I am leaning toward Option 1.  
I am adding tracking the Sku so I have the maximum run rate for OEE.

**Option 1**  
One table

Columns:  
ndx, t\_stamp, location, machine, event code, quantity, sku

Triggers  
When a new state event or reject event happens, the sku is logged.  
When a sku changes, the state is logged

**Option 2**  
3 event tables

Stop events columns:  
ndx, t\_stamp, location, machine, stop code

Reject events columns:  
ndx, t\_stamp, location, machine, reject code, quantity

Sku events columns:  
ndx, t\_stamp, location, machine, sku

**Option 1 query**

```auto
SELECT 
    sku,
    SUM(CASE WHEN event_code = 'Stop' THEN 1 ELSE 0 END) AS total_stops,
    SUM(CASE WHEN event_code = 'Reject' THEN quantity_or_sku ELSE 0 END) AS total_rejects
FROM 
    your_table
WHERE 
    t_stamp BETWEEN '2024-03-20 08:00:00' AND '2024-03-20 09:00:00'
GROUP BY 
    sku;

```

**Option 2 query**

```auto
SELECT 
    sk.sku,
    SUM(CASE WHEN s.event_code = 'Stop' THEN 1 ELSE 0 END) AS total_stops,
    SUM(CASE WHEN r.reject_code IS NOT NULL THEN 1 ELSE 0 END) AS total_rejects
FROM 
    sku_events sk
LEFT JOIN 
    stop_events s ON sk.ndx = s.ndx AND s.t_stamp BETWEEN '2024-03-20 08:00:00' AND '2024-03-20 09:00:00'
LEFT JOIN 
    reject_events r ON sk.ndx = r.ndx AND r.t_stamp BETWEEN '2024-03-20 08:00:00' AND '2024-03-20 09:00:00'
GROUP BY 
    sk.sku;

```

I need help evaluating benefits of Option 2.  
I only know that it may have faster indexed inserts, not sure.

I learned to go with a single table before with the events tables.  
I had used a single table with states and rejects in one table before.

Though I did see some comments about separating those tables.  
I still don't understand why to separate them, or is it just the insert speed?  
[Organizing SQL tables and named queries efficiently - #11 by zacharyw.larson](https://forum.inductiveautomation.com/t/organizing-sql-tables-and-named-queries-efficiently/53212/11)]

---

_[View the full topic](https://forum.inductiveautomation.com/t/getting-max-run-rate/87217)._
