Use CasesAISQL

Customer Segmentation Without SQL: Query Your Database by Any Criteria

Customer segmentation is one of the highest-leverage things a business can do. Send the right message to the right customer at the right time, and conversion...

Marcus Chen· Solutions EngineerMarch 28, 20269 min read

Customer segmentation is one of the highest-leverage things a business can do. Send the right message to the right customer at the right time, and conversion rates go up. Onboard new users differently based on their company size, and activation improves. Identify at-risk accounts before they churn, and retention increases.

The problem: most segmentation tools either require SQL knowledge to query your database directly, or they only let you segment by data that's been synced into a CRM or marketing platform. If your source of truth is a database, and it often is, you're stuck.

This guide covers practical approaches to customer segmentation directly from a database no SQL required.

Why Your Database Is the Best Segmentation Source

Your CRM and marketing tools show you a curated subset of your customer data. They know what you've explicitly synced: contact info, deal stage, last email open. But they don't know:

  • Which features a user has actually activated
  • How many times they've hit an error in the last 7 days
  • Whether their usage is trending up or down
  • What their actual revenue contribution was last month (not what the CRM estimates)
  • Which customers share a billing address or payment method (useful for account deduplication)
  • All of that lives in your database. The customers table, the events table, the subscriptions table, the invoices table together they give you a complete behavioral and financial picture that no CRM has.

    Segmentation based on real behavioral data is more accurate and more actionable than segmentation based on CRM fields someone remembered to update.

    Common Segmentation Criteria and the SQL Behind Them

    Even if you're not writing SQL yourself, it's useful to understand what the underlying logic looks like. Here's what common segmentation criteria translate to:

    By usage level (power users vs. at-risk):

    SELECT
      user_id,
      COUNT(event_id) AS events_last_30_days,
      CASE
        WHEN COUNT(event_id) >= 100 THEN 'power_user'
        WHEN COUNT(event_id) >= 20 THEN 'active'
        WHEN COUNT(event_id) >= 1 THEN 'low_usage'
        ELSE 'dormant'
      END AS usage_tier
    FROM user_events
    WHERE created_at >= NOW() - INTERVAL '30 days'
    GROUP BY user_id;

    By plan type and tenure:

    SELECT
      u.id,
      u.email,
      s.plan_name,
      DATE_PART('day', NOW() - u.created_at) AS days_since_signup
    FROM users u
    JOIN subscriptions s ON s.user_id = u.id
    WHERE s.status = 'active'
      AND s.plan_name = 'pro'
      AND u.created_at < NOW() - INTERVAL '90 days';

    By churn risk (no activity in 14+ days, was previously active):

    SELECT
      user_id,
      MAX(created_at) AS last_active,
      DATE_PART('day', NOW() - MAX(created_at)) AS days_inactive
    FROM user_events
    GROUP BY user_id
    HAVING MAX(created_at) < NOW() - INTERVAL '14 days'
       AND MAX(created_at) > NOW() - INTERVAL '60 days';

    When you use a tool like AI for Database, you don't type any of this. You type "Show me users who were active last month but haven't done anything in the past 14 days" and get the result directly.

    Five Segments Every SaaS Should Build

    1. Activation-complete vs. not yet activated

    Define what "activated" means for your product completed the setup wizard, connected an integration, invited a teammate, ran their first query. Then query for users who signed up in the last 30 days and split them: activated vs. not.

    This segment is the single most important thing to measure in early growth. Activation rate determines whether your acquisition spending is turning into retained users or a leaky bucket.

    Ask: "Show me users who signed up in the last 30 days, split by whether they've completed their first [key action]."

    2. High-value accounts at risk of churning

    Combine revenue data with activity data. Find accounts with a subscription value above a threshold whose usage has dropped more than 40% in the last 30 days compared to the previous 30 days.

    These are customers worth a personal outreach from a customer success manager. They're likely evaluating alternatives or have hit a problem they haven't reported.

    Ask: "Find active Pro or Enterprise accounts where monthly usage is down more than 40% compared to last month."

    3. Ready-to-upgrade users

    Identify users on a free or lower tier who are hitting the limits of that tier high usage, multiple team members, frequent sessions. These users have demonstrated value but haven't been prompted to upgrade at the right moment.

    Ask: "Show me users on the free plan who have logged in more than 20 times this month."

    4. Champions users who've referred others

    If your product has a referral or invite mechanism, find users who've invited team members or referred new signups. These are your product champions. They're worth nurturing for case studies, testimonials, or higher-tier features.

    Ask: "Show me users who have invited at least 2 other users to the platform in the last 60 days."

    5. Long-tenured but underutilizing

    Customers who've been around for 12+ months but use only a fraction of the features available to them. They're not at imminent churn risk, but they're not getting full value. A targeted educational campaign a webinar, a short tutorial, a feature spotlight can re-engage them.

    Ask: "List users with accounts older than 12 months who have only used 1 out of the 5 core features."

    Using Segmentation for Automated Actions

    Identifying segments is only half the work. The other half is doing something with them.

    With AI for Database's workflow feature, you can turn a segment query into an automated action:

  • When a user enters the "at-risk" segment → trigger a webhook to your email platform → send a re-engagement email
  • When a free user crosses the usage threshold → notify the sales team via Slack → add to a CRM sequence
  • When an account's usage drops 50% week-over-week → alert the assigned CSM
  • This is the difference between retrospective reporting ("here are the customers who churned last quarter") and proactive intervention ("here are the customers showing early churn signals right now").

    The workflow checks your database on a schedule. You define the condition in plain English, set the trigger threshold, and connect the action. No stored procedures, no cron jobs, no Zapier chains.

    Exporting Segments for Use in Other Tools

    Once you've identified a segment, you typically need to use it somewhere: load it into your email platform, create a CRM task list, or pass it to your ad platform for a retargeting audience.

    Common patterns:

    Email campaign targeting: Export a CSV of email addresses for the segment and upload to Mailchimp, ActiveCampaign, or whatever you use. Or trigger the email directly via webhook.

    CRM enrichment: Run a query that returns account IDs, then update a field in your CRM via its API. For example, set churn_risk = high on accounts that hit your at-risk criteria.

    Slack notification: Use a webhook action to post a daily digest: "3 new accounts crossed the upgrade threshold today: [list]."

    Ad platform retargeting: Export a list of user emails to upload as a custom audience in Facebook or Google Ads. Target your high-usage free users with upgrade messaging.

    The database is already the most up-to-date version of customer reality. Getting that data flowing outward to the tools your team actually uses is where segmentation produces business results.

    Keeping Segmentation Current Without Manual Work

    The dirty secret of most segmentation efforts: they're done once, then immediately go stale. Someone builds "the at-risk cohort" in Q1, presents it in a board meeting, and it never gets refreshed.

    The fix is automation. Use AI for Database to create dashboard panels that re-run your segment queries on a schedule. Instead of "here's the at-risk cohort as of last February," you have "here are the at-risk accounts right now, updated daily."

    Pair this with alert-based workflows and you get a system that:

  • Continuously re-evaluates all customers against segment criteria
  • Notifies relevant teams when customers enter or exit key segments
  • Triggers downstream actions automatically
  • This turns segmentation from a periodic project into a continuous operating system.

    Getting Your First Segment Running

    The fastest way to start is to pick one high-value segment churn risk is usually the most impactful and build it today.

  • Connect your database to AI for Database
  • Ask: "Show me active paying customers who haven't logged in for 14 or more days"
  • Review the results, verify the logic looks right
  • Save it as a dashboard panel that refreshes daily
  • Set up a Slack alert for when new accounts enter this segment
  • That's a functioning early-warning system for churn, built in under 20 minutes without writing SQL.

    Customer segmentation is most useful when it's continuous, not a quarterly project. Starting with your live database and automating the refresh is the fastest path from "we have a lot of customer data" to "we're actually using it."

    Try AI for Database free at aifordatabase.com

    Ready to try AI for Database?

    Query your database in plain English. No SQL required. Start free today.