Common SQL Queries (on-going)
Last Month Metrics or Data
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
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
Getting last month's sale by individual shopfronts for an instance
Getting last month's sale by hub shopfronts for an instance
PreviousCreating Customers (with Tags) on OFN using V1 API with data from a CSV/XLSX fileNextGlobal Metrics Dashboard
Last updated