class DailySignupRollup < ApplicationRecord
validates :day, presence: true, uniqueness: true
validates :total, :verified, numericality: { greater_than_or_equal_to: 0 }
scope :for_range, ->(from, to) do
where(day: from.to_date..to.to_date).order(:day)
-- ROLLUP for hierarchical subtotals
SELECT
COALESCE(category, 'ALL CATEGORIES') AS category,
COALESCE(subcategory, 'ALL SUBCATEGORIES') AS subcategory,
SUM(revenue) AS total_revenue,
COUNT(*) AS order_count