Common SQL Queries (on-going)
Last Month Metrics or Data
You can get data for any number of past months by changing -1 month in the SQL query {"(INTERVAL '-1 month')"} to the number of months you need it for. Data will be grouped by month.
Getting last month sales for an instance
SELECT date_trunc('month', "public"."spree_orders"."completed_at") AS "completed_at", sum("public"."spree_orders"."total") AS "value"|FROM "public"."spree_orders"WHERE ("public"."spree_orders"."state" = 'complete' AND "public"."spree_orders"."completed_at" >= date_trunc('month', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 month')) AS timestamp)) AND "public"."spree_orders"."completed_at" < date_trunc('month', CAST(now() AS timestamp)))GROUP BY date_trunc('month', "public"."spree_orders"."completed_at")ORDER BY date_trunc('month', "public"."spree_orders"."completed_at") ASCGetting last month's completed orders for an instance
SELECT date_trunc('month', "public"."spree_orders"."completed_at") AS "completed_at", count(*) AS "value" FROM "public"."spree_orders" WHERE ("public"."spree_orders"."state" = 'complete' AND "public"."spree_orders"."completed_at" >= date_trunc('month', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 month')) AS timestamp)) AND "public"."spree_orders"."completed_at" < date_trunc('month', CAST(now() AS timestamp))) GROUP BY date_trunc('month', "public"."spree_orders"."completed_at") ORDER BY date_trunc('month', "public"."spree_orders"."completed_at") ASCGetting last month's new enterprise signups for an instance
SELECT date_trunc('month', "public"."enterprises"."created_at") AS "created_at", count(distinct "public"."enterprises"."id") AS "value"|FROM "public"."enterprises"WHERE ("public"."enterprises"."created_at" >= date_trunc('month', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 month')) AS timestamp)) AND "public"."enterprises"."created_at" < date_trunc('month', CAST(now() AS timestamp)))GROUP BY date_trunc('month', "public"."enterprises"."created_at")ORDER BY date_trunc('month', "public"."enterprises"."created_at") ASCGetting number of shoppers with a completed order in last month for an instance
SELECT date_trunc('month', "public"."spree_orders"."completed_at") AS "completed_at", count(distinct "public"."spree_orders"."email") AS "value"|FROM "public"."spree_orders"WHERE ("public"."spree_orders"."state" = 'complete' AND "public"."spree_orders"."completed_at" >= date_trunc('month', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 month')) AS timestamp)) AND "public"."spree_orders"."completed_at" < date_trunc('month', CAST(now() AS timestamp)))GROUP BY date_trunc('month', "public"."spree_orders"."completed_at")ORDER BY date_trunc('month', "public"."spree_orders"."completed_at") ASCGetting number of Active Shopfronts in last month for an instance
Number of shopfronts/shops with at least 1 completed order (can incl. test orders) from their shop
SELECT date_trunc('month', "Spree Orders"."completed_at") AS "completed_at", count(distinct "public"."enterprises"."id") AS "value"|FROM "public"."enterprises"LEFT JOIN "public"."spree_orders" "Spree Orders" ON "public"."enterprises"."id" = "Spree Orders"."distributor_id"WHERE ("Spree Orders"."state" = 'complete' AND "Spree Orders"."completed_at" >= date_trunc('month', CAST((CAST(now() AS timestamp) + (INTERVAL '-1 month')) AS timestamp)) AND "Spree Orders"."completed_at" < date_trunc('month', CAST(now() AS timestamp)))GROUP BY date_trunc('month', "Spree Orders"."completed_at")ORDER BY date_trunc('month', "Spree Orders"."completed_at") ASCGetting number of Active Producers in last month for an instance
Number of producers who has an item sold in the last month via any shop
Getting last month's sale by individual shopfronts for an instance
Shop filter: Sells = own
Getting last month's sale by hub shopfronts for an instance
Shop filter: Sells = any
PreviousCreating Customers (with Tags) on OFN using V1 API with data from a CSV/XLSX file
NextGlobal Metrics Dashboard
Last updated