| 338 | | γ modification_id, product_id; |
| 339 | | units_sold_before := SUM(op.quantity), |
| 340 | | revenue_before := SUM(op.quantity * op.price_at_purchase) |
| 341 | | ( |
| 342 | | σ o.purchase_date ∈ [m.date_modified - 30 days, m.date_modified) |
| 343 | | ∧ o.status ∈ {PAID, SHIPPED, DELIVERED} |
| 344 | | ( |
| 345 | | DiscountEvents de ⨝ ORDER_PRODUCTS op ⨝ ORDERS o |
| 346 | | ) |
| | 345 | γ de.modification_id, de.product_id; |
| | 346 | units_sold_before := COALESCE(SUM(op.quantity), 0), |
| | 347 | revenue_before := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00) |
| | 348 | ( |
| | 349 | ( |
| | 350 | DiscountEvents de |
| | 351 | ⟕ (de.product_id = op.product_id) ORDER_PRODUCTS op |
| | 352 | ) |
| | 353 | ⟕ ( |
| | 354 | op.order_id = o.order_id |
| | 355 | ∧ o.purchase_date >= de.date_modified - 30 days |
| | 356 | ∧ o.purchase_date < de.date_modified |
| | 357 | ∧ o.status ∈ {PAID, SHIPPED, DELIVERED} |
| | 358 | ) ORDERS o |
| 350 | | γ modification_id, product_id; |
| 351 | | units_sold_after := SUM(op.quantity), |
| 352 | | revenue_after := SUM(op.quantity * op.price_at_purchase) |
| 353 | | ( |
| 354 | | σ o.purchase_date ∈ (m.date_modified, m.date_modified + 30 days] |
| 355 | | ∧ o.status ∈ {PAID, SHIPPED, DELIVERED} |
| 356 | | ( |
| 357 | | DiscountEvents de ⨝ ORDER_PRODUCTS op ⨝ ORDERS o |
| 358 | | ) |
| | 362 | γ de.modification_id, de.product_id; |
| | 363 | units_sold_after := COALESCE(SUM(op.quantity), 0), |
| | 364 | revenue_after := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00) |
| | 365 | ( |
| | 366 | ( |
| | 367 | DiscountEvents de |
| | 368 | ⟕ (de.product_id = op.product_id) ORDER_PRODUCTS op |
| | 369 | ) |
| | 370 | ⟕ ( |
| | 371 | op.order_id = o.order_id |
| | 372 | ∧ o.purchase_date > de.date_modified |
| | 373 | ∧ o.purchase_date <= de.date_modified + 30 days |
| | 374 | ∧ o.status ∈ {PAID, SHIPPED, DELIVERED} |
| | 375 | ) ORDERS o |
| 382 | | τ promotion_start_date ↓, net_revenue_impact ↓ |
| 383 | | ( |
| 384 | | π *, |
| 385 | | promotion_verdict := |
| 386 | | CASE |
| 387 | | WHEN net_revenue_impact > 0 ∧ volume_change > 0 |
| 388 | | THEN 'SUCCESS' |
| 389 | | WHEN net_revenue_impact < 0 ∧ volume_change > 0 |
| 390 | | THEN 'MARGIN LOSS' |
| 391 | | WHEN volume_change <= 0 |
| 392 | | THEN 'FAILURE' |
| 393 | | ELSE 'NEUTRAL' |
| 394 | | END |
| 395 | | ( |
| 396 | | PromoSummary |
| 397 | | ) |
| 398 | | ) |
| | 399 | π product_id, |
| | 400 | release_title, |
| | 401 | product_format, |
| | 402 | promotion_start_date, |
| | 403 | discount_applied, |
| | 404 | units_sold_before, |
| | 405 | units_sold_after, |
| | 406 | volume_change, |
| | 407 | revenue_before, |
| | 408 | revenue_after, |
| | 409 | net_revenue_impact, |
| | 410 | promotion_verdict := |
| | 411 | CASE |
| | 412 | WHEN net_revenue_impact > 0 ∧ volume_change > 0 |
| | 413 | THEN 'SUCCESS: Volume generated profit' |
| | 414 | WHEN net_revenue_impact < 0 ∧ volume_change > 0 |
| | 415 | THEN 'MARGIN LOSS: Volume rose but lost overall revenue' |
| | 416 | WHEN volume_change <= 0 |
| | 417 | THEN 'FAILURE: No demand increase observed' |
| | 418 | ELSE 'NEUTRAL' |
| | 419 | END |
| | 420 | ( |
| | 421 | PromoSummary |
| | 422 | ) |
| | 423 | |
| | 424 | τ promotion_start_date ↓, net_revenue_impact ↓ (Result) |
| 482 | | γ user_id; |
| 483 | | total_orders_placed := COUNT(order_id), |
| 484 | | lifetime_points_earned := SUM(points_earned), |
| 485 | | lifetime_points_burned := SUM(points_used), |
| 486 | | total_monetary_spend := SUM(op.quantity * op.price_at_purchase) |
| 487 | | ( |
| 488 | | σ o.purchase_date >= NOW - 2 years |
| | 508 | γ o.user_id; |
| | 509 | total_orders_placed := COUNT(o.order_id), |
| | 510 | lifetime_points_earned := COALESCE(SUM(o.points_earned), 0), |
| | 511 | lifetime_points_burned := COALESCE(SUM(o.points_used), 0), |
| | 512 | total_monetary_spend := COALESCE(SUM(op.quantity * op.price_at_purchase), 0.00) |
| | 513 | ( |
| | 514 | σ o.purchase_date >= CURRENT_DATE - 2 years |
| 523 | | τ account_creation_vintage ↓, current_unspent_points_balance ↓ |
| 524 | | ( |
| 525 | | π user_id, username, email, |
| 526 | | account_creation_vintage, |
| 527 | | registration_date, |
| 528 | | orders_count_2yr, |
| 529 | | lifetime_spend_amount, |
| 530 | | current_unspent_points_balance, |
| 531 | | points_earned_2yr, |
| 532 | | points_burned_2yr, |
| 533 | | customer_retention_segment := |
| 534 | | CASE |
| 535 | | WHEN is_vip = 1 THEN 'VIP' |
| 536 | | WHEN is_hoarder = 1 THEN 'HOARDER' |
| 537 | | WHEN is_churned = 1 THEN 'CHURNED' |
| 538 | | ELSE 'STANDARD' |
| 539 | | END |
| 540 | | ( |
| 541 | | UserFlags |
| 542 | | ) |
| 543 | | ) |
| 544 | | }}} |
| 545 | | |
| 546 | | |
| | 553 | π user_id, |
| | 554 | username, |
| | 555 | email, |
| | 556 | account_creation_vintage, |
| | 557 | registration_date, |
| | 558 | orders_count_2yr, |
| | 559 | lifetime_spend_amount, |
| | 560 | current_unspent_points_balance, |
| | 561 | points_earned_2yr, |
| | 562 | points_burned_2yr, |
| | 563 | customer_retention_segment := |
| | 564 | CASE |
| | 565 | WHEN is_vip = 1 THEN 'VIP Tier: High Future Discount Liability' |
| | 566 | WHEN is_hoarder = 1 THEN 'Points Hoarder: Inactive Burn (High Risk)' |
| | 567 | WHEN is_churned = 1 THEN 'Churned After Reward Use (No Retention)' |
| | 568 | ELSE 'Standard Active Engagement Profile' |
| | 569 | END |
| | 570 | ( |
| | 571 | UserFlags |
| | 572 | ) |
| | 573 | |
| | 574 | τ account_creation_vintage ↓, current_unspent_points_balance ↓ (Result) |
| | 575 | }}} |
| | 576 | |
| | 577 | |