Most HR teams are sitting on a goldmine of data they can't access. Headcount by department, time-to-hire, attrition rates by tenure it's all in your database. But getting to it means filing a ticket with engineering, waiting three days, and then getting a static spreadsheet that's already out of date.
This guide shows HR teams and People Ops managers how to pull meaningful workforce metrics directly from their database without writing a single line of SQL. We'll cover the questions worth asking, the data that answers them, and how tools like AI for Database make the whole process as simple as typing a message.
Why HR Data Lives in the Database (Not Just in Your HRIS)
Your HRIS whether it's BambooHR, Workday, or Rippling gives you canned reports. But the raw data underneath tells a richer story. When employees are created, updated, or terminated, those events hit a database. So does every job requisition, offer letter, onboarding task completion, and payroll run.
A typical HR schema might look like this:
-- employees table
SELECT id, name, department, hire_date, termination_date, manager_id, salary
FROM employees
WHERE termination_date IS NULL;
-- job_requisitions table
SELECT id, title, department, opened_at, closed_at, hired_employee_id
FROM job_requisitions;The problem isn't that the data doesn't exist. It's that most HR professionals don't write SQL and they shouldn't have to.
The Metrics That Actually Matter (and How to Ask for Them)
Here are five workforce metrics HR teams track constantly, and the natural-language questions that surface them.
1. Current Headcount by Department
Ask: "How many active employees do we have in each department?"
The underlying query groups employees who don't have a termination date, by department. In plain SQL:
SELECT department, COUNT(*) AS headcount
FROM employees
WHERE termination_date IS NULL
GROUP BY department
ORDER BY headcount DESC;With AI for Database, you type that question in plain English and get a table back no query needed.
2. Monthly Attrition Rate
Ask: "What was our employee attrition rate each month for the past year?"
Attrition = employees who left / average headcount for that period. This requires a slightly complex calculation, but the AI handles it:
SELECT
DATE_TRUNC('month', termination_date) AS month,
COUNT(*) AS terminations,
ROUND(COUNT(*) * 100.0 / AVG(total_headcount), 2) AS attrition_rate
FROM employees
JOIN (
SELECT DATE_TRUNC('month', hire_date) AS month, COUNT(*) AS total_headcount
FROM employees GROUP BY 1
) AS hc ON DATE_TRUNC('month', termination_date) = hc.month
WHERE termination_date IS NOT NULL
GROUP BY 1
ORDER BY 1;The kind of query you'd normally ask an analyst to write. With natural language tools, you get the same result in seconds.
3. Time-to-Hire by Role Type
Ask: "What's the average time from job opening to hire for engineering vs. sales roles in the past 6 months?"
SELECT
CASE
WHEN title ILIKE '%engineer%' OR title ILIKE '%developer%' THEN 'Engineering'
WHEN title ILIKE '%sales%' OR title ILIKE '%account%' THEN 'Sales'
ELSE 'Other'
END AS role_type,
ROUND(AVG(EXTRACT(DAY FROM closed_at - opened_at)), 1) AS avg_days_to_hire
FROM job_requisitions
WHERE closed_at IS NOT NULL
AND opened_at > NOW() - INTERVAL '6 months'
GROUP BY role_type;Knowing that engineering roles take 42 days vs. 18 days for sales changes how you resource your recruiting team.
4. Tenure Distribution at Departure
Ask: "Among employees who left in the past 12 months, what was the average tenure at time of departure?"
This tells you whether you're losing people early (onboarding problem) or mid-career (management problem).
SELECT
ROUND(AVG(
EXTRACT(DAY FROM termination_date - hire_date) / 365.0
), 1) AS avg_tenure_years,
COUNT(*) AS total_departures
FROM employees
WHERE termination_date BETWEEN NOW() - INTERVAL '12 months' AND NOW();5. Compensation Spread by Department
Ask: "Show me the min, max, and median salary by department for active employees."
Identifying pay compression or outliers before they become retention problems.
SELECT
department,
MIN(salary) AS min_salary,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary,
MAX(salary) AS max_salary
FROM employees
WHERE termination_date IS NULL
GROUP BY department;Building a Self-Refreshing HR Dashboard
One-off queries are useful. But what HR really needs is a dashboard that stays current one that shows today's headcount, this month's attrition, and open roles without anyone having to run a report.
AI for Database lets you build these dashboards from plain-English descriptions. You describe the chart you want "Monthly new hires vs. terminations as a bar chart" and it writes the query, renders the chart, and refreshes it on whatever schedule you set. Daily, weekly, or in real time.
That means when leadership asks "how are we tracking against our hiring plan?" you have an answer in 10 seconds, not 10 business days.
A useful starting dashboard for any People team might include:
Setting Up Alerts for Workforce Signals
Some HR metrics aren't just things you want to see they're things you need to be notified about. AI for Database's action workflows let you define conditions and trigger messages or emails automatically.
Examples worth automating:
These run against your live database, fire automatically, and don't require any DBA work, stored procedures, or custom scripts.
Connecting Your HR Database
AI for Database connects to any standard database: PostgreSQL, MySQL, SQLite, MongoDB, Supabase, MS SQL Server, BigQuery, and more. If your HRIS exports to a database or you manage your own HR data store, you can connect it in under two minutes just supply the connection string and the AI handles the rest.
For teams using Supabase as their backend (increasingly common with modern HR tools), the connection is especially simple: just paste in your Supabase connection string and you're live.
What This Changes for People Teams
The shift from "file a ticket and wait" to "ask and get an answer" is significant for HR. It means:
This isn't about replacing HR systems it's about making the data that's already in those systems actually accessible to the people who need it.
If you want to try it with your own HR data, AI for Database has a free tier. Connect your database, ask your first question in plain English, and see what comes back.