MySQL · SQL · Excel — 2026
Employee Database Analysis
Workforce composition and pay distribution across a 240K-record relational HR database.
Objective
Where does headcount concentrate, and which departments carry the highest average salary exposure?
A normalized employee database was queried across employee, department, salary, and title tables. Joins, filtering, grouping, and aggregate functions were used to profile the current workforce, then reconciled in Excel to confirm record counts and salary aggregates.
- Current employees
- 240,124
- Largest department
- Development
- Top average salary
- $88,853
- Tables joined
- 5
Active records after date filtering
61,386 employees
Sales department
employees, dept_emp, departments, salaries, titles
Analysis
Method and query logic
Step 1
Scope the current population
Salary and department assignment tables are effective-dated. Every query filters on the open-ended end date so headcount reflects current employees, not the full historical record.
Step 2
Join across the entity graph
Employees join to department assignment, then to department names, then to salary and title history using primary/foreign key relationships.
Step 3
Aggregate and rank
GROUP BY department with COUNT and AVG, ordered descending, to produce headcount and average current salary side by side.
Step 4
Reconcile
Results were exported to Excel and re-totaled independently to confirm the aggregate row counts matched the source tables.
SELECT
d.dept_name AS department,
COUNT(DISTINCT e.emp_no) AS employees,
ROUND(AVG(s.salary), 0) AS avg_current_salary
FROM employees AS e
JOIN dept_emp AS de ON de.emp_no = e.emp_no
JOIN departments AS d ON d.dept_no = de.dept_no
JOIN salaries AS s ON s.emp_no = e.emp_no
WHERE de.to_date = '9999-01-01' -- current department assignment
AND s.to_date = '9999-01-01' -- current salary record
GROUP BY d.dept_name
ORDER BY employees DESC;Results
Key findings
Headcount by department
Current employees per department. Development and Production hold the majority of the workforce.
Average current salary by department
Sales and Marketing lead on average pay while sitting well below Development on headcount — pay concentration and people concentration do not sit in the same place.
- 240,124 employees are currently active once effective-dated rows are filtered — roughly 20K fewer than the raw employee table implies.
- Development is the largest department at 61,386 people, about 26% of the active workforce.
- Sales carries the highest average current salary at approximately $88,853, about 31% above Development.
- Headcount rank and salary rank are close to inverted: the three largest departments all sit in the bottom half on average pay.
Business impact
Recommendation
Total salary exposure is driven by Development's volume, but per-head cost risk sits in Sales and Marketing — a merit-increase pool sized on headcount alone would misallocate.
Any workforce KPI built on the raw employee table without the date filter overstates headcount by roughly 8%.
Limitations
- — Salary history is point-in-time; this analysis reports the current record only and does not model raise velocity.
- — Title-level seniority mix is not held constant, so department pay gaps partly reflect role composition rather than pay policy.