I'm glad you caught that! That would be another subtle bug. That's what I get for going off the top of my head and using copy paste (thus propagating the error on and on). As to myself, no SQL expert here. I've just done enough headbanging with SQL that I know some of the pitfalls (but only some).
You know a heck more than I. I NEVER would have figured that out on my own... Spent ALL day yesterday trying. Simple when you look at it - hard to explain to others what the REAL issue is.
Thanks for everyone's input.
That produces EXACTLY what I need, in it's basic form.
I shall have to limit the date range at some point AND restrict to a certain company ID (multi-tenant).
Now - add a timer, update the jar to my remote server and start throwing data at it from my Android devices and see how it responds...
Lookin good.