Skip to content

Instantly share code, notes, and snippets.

View AcousticRand's full-sized avatar

Rand Thacker AcousticRand

  • Helen Of Troy
  • 17:52 (UTC -05:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am acousticrand on github.
  • I am rthacker (https://keybase.io/rthacker) on keybase.
  • I have a public key ASCCsGMWkQPUGD0-qUQCZbcMDSyfSxsJUpAYT5h0-9gN0wo

To claim this, I am signing this object:

@AcousticRand
AcousticRand / OrderVelocity.sql
Created March 14, 2017 22:53
Calculate order velocity in any order database (orders per second, orders per minute, orders per hour, orders per day)
SET @end_time = utc_timestamp(), @start_time = '2017-03-14 15:00:00'; -- specific start time
-- SET @end_time = utc_timestamp(), @start_time = date_sub(@end_time, INTERVAL '02:30' HOUR_MINUTE); -- interval start time last 2.5 hours
SELECT
COUNT(id) AS OrdersPer
-- , DATE_FORMAT(CONVERT_TZ(OrderDate, 'UTC', 'EST'), "%Y-%m-%d %H:%i:%s") AS time_buckets -- Use this one for ORDERS PER SECOND
, DATE_FORMAT(CONVERT_TZ(OrderDate, 'UTC', 'EST'), "%Y-%m-%d %H:%i") AS time_buckets -- Use this one for ORDERS PER MINUTE
-- , DATE_FORMAT(CONVERT_TZ(OrderDate, 'UTC', 'EST'), "%Y-%m-%d %H") AS time_buckets -- Use this one for ORDERS PER HOUR
-- , DATE_FORMAT(CONVERT_TZ(OrderDate, 'UTC', 'EST'), "%Y-%m-%d") AS time_buckets -- Use this one for ORDERS PER DAY
-- , now() -- if you would like to see the timezone of now in the DB server's TZ (likely UTC) for comparison