I have a JDBC database (DB2 specifically but am looking for something DB agnostic, at a minimum DB2 and Oracle) that has a table that, every 10 minutes, gets records inserted with statistics about APIs that are run by the application in question. It looks something like:

```
StatKey, StartDate, EndDate, APIName, StatName, StatValue
201505071498224437562706    2015-05-07 14:12:44.0   2015-05-07 14:22:44.0   API5    Invocations 34
201505071498161437466684    2015-05-07 14:06:14.0   2015-05-07 14:16:14.0   API4    Invocations 79
201505071498060937466556    2015-05-07 13:56:08.0   2015-05-07 14:06:08.0   API4    Average 26,264.37
201505071497263437627286    2015-05-07 14:16:33.0   2015-05-07 14:26:34.0   API2    Invocations 24
201505071497262137620812    2015-05-07 14:16:19.0   2015-05-07 14:26:20.0   API2    Invocations 24
201505071497024537466378    2015-05-07 13:52:43.0   2015-05-07 14:02:44.0   API1    Average 6,830,050
201505071497023337466368    2015-05-07 13:52:31.0   2015-05-07 14:02:32.0   API3    Average 31,523
201505071496023337466361    2015-05-07 13:52:31.0   2015-05-07 14:02:32.0   API2    Invocations 1
201505071494263837628892    2015-05-07 14:16:36.0   2015-05-07 14:26:37.0   API5    Invocations 68
201505071493124437466656    2015-05-07 14:02:44.0   2015-05-07 14:12:44.0   API1    Invocations 2
201505071492263037625304    2015-05-07 14:16:29.0   2015-05-07 14:26:30.0   API3    Average 179,223.29

```

Every 10 minutes, any API executed during that time will have an entry similar to the above. However, multiple JVMs will write to the same database so the start and end times are not simply every 10 minutes and there could be more than 6 entries every hour.

What I'm trying to do is create a SQL that will group per hour all invocations of all API for each hour of run time. For example:

```
Date&Hour, API, Invocations
2015-05-07 12:00, API1, 100
2015-05-07 12:00, API2, 150
2015-05-07 13:00, API2, 200
etc...

```

I've tried doing a GROUP BY based on a SUBSTR of the primary key (which is always the timestamp plus some random numbers - but between the hours and minutes are 2 random digits) at the hour mark but I'm not sure how to add all StatName=Invocations per hour.

Could someone please provide some ideas as to how I might accomplish this?