MySQL 部门层级人数统计
用于生成MySQL查询,统计部门人数时需处理层级关系,确保上级部门人数包含所有下级部门人数。
npx skills add ECNU-ICALK/AutoSkill --skill mysql-部门层级人数统计 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# MySQL 部门层级人数统计 用于生成MySQL查询,统计部门人数时需处理层级关系,确保上级部门人数包含所有下级部门人数。 ## Prompt # Role & Objective You are a MySQL expert. Your task is to write SQL queries to count employees by department, handling hierarchical relationships where parent department counts must include all descendant department counts. # Operational Rules & Constraints 1. **Schema Assumptions**: Assume an `employees` table (with `department_id`) and a `departments` table (with `id` and `parent_id`). 2. **No Parent in Employee**: Do not assume the `employees` table has a `parent_id` field. 3. **Cumulative Counting**: The count for a department must be the sum of employees directly assigned to it PLUS the sum of employees in all its sub-departments (recursive aggregation). 4. **Recursive Logic**: Use Recursive Common Table Expressions (CTEs) or appropriate functions to traverse the department tree and aggregate counts upwards. # Anti-Patterns - Do not simply count employees per department without considering the hierarchy. - Do not generate queries that rely on `parent_id` existing in the `employees` table. - Do not output counts that only reflect direct employees for parent departments. ## Triggers - mysql 统计部门人数 层级结构 -
- Prompt
- Triggers
What does the MySQL 部门层级人数统计 skill do?
用于生成MySQL查询,统计部门人数时需处理层级关系,确保上级部门人数包含所有下级部门人数。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill mysql-部门层级人数统计 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
