Skip to main content

Advanced People Queries

Master complex SQL patterns for deep insights into your congregation. These queries combine multiple tables, use window functions, and employ advanced techniques for comprehensive analysis.

Query Customization Required

These example queries demonstrate common patterns but may require adjustments to match your specific database schema and field names. Test thoroughly in your environment before use.

Query Requirements

Schema Prefix

IMPORTANT: All tables in the Planning Center People module live in the planning_center schema. Always prefix table names with planning_center. in your queries. ✅ CORRECT: SELECT * FROM planning_center.people_people ❌ INCORRECT: SELECT * FROM people_people

Row Level Security (RLS)

Row Level Security automatically filters results for:
  • tenant_organization_id – only your organization’s data
  • system_status – active records returned by default
Do not add these filters manually—RLS already enforces them and redundant predicates can hide data or slow execution:
  • WHERE tenant_organization_id = 1
  • WHERE system_status = 'active'
Focus your filters on ministry-specific status, engagement, and demographic criteria while relying on RLS for tenancy and system status.

Table of Contents

Demographic Analysis

Comprehensive Demographic Breakdown

Geographic Distribution Analysis

Engagement Scoring

Multi-Factor Engagement Score

Engagement Trajectory

Family Analytics

Family Composition Analysis

Multi-Generational Households

Growth and Retention

Cohort Retention Analysis

Growth Velocity Analysis

Communication Optimization

Communication Preference Analysis

Volunteer Management

Volunteer Capacity Analysis

Predictive Analytics

Churn Risk Prediction

Performance Optimization

Materialized View for Dashboard

Best Practices

  1. Use CTEs for Clarity: Break complex queries into logical steps
  2. Leverage Window Functions: Use OVER() for running totals and comparisons
  3. Filter Early: Apply WHERE clauses as early as possible
  4. Index Strategic Columns: Ensure frequently joined/filtered columns are indexed
  5. Monitor Query Performance: Use EXPLAIN ANALYZE for optimization

Next Steps

Apply these advanced queries to real ministry scenarios: