Employee Query Activity Analysis
Beginner Mode
Objective
Write a SQL query to create a histogram of employee query activity for Q3 2023.
Table Schema:
- employees
| Column | Type | Description |
|---|---|---|
| employee_id | INTEGER | Unique identifier for each employee |
| employee_name | VARCHAR | Name of the employee |
- queries
| Column | Type | Description |
|---|---|---|
| query_id | INTEGER | Unique identifier for each query |
| employee_id | INTEGER | ID of the employee who executed the query |
| query_text | TEXT | The SQL query text |
| execution_date | DATETIME | Date and time when the query was executed |
Task Requirements:
- Filter queries executed in Q3 2023 (July, August, September)
- Count unique queries per employee
- Include employees who executed zero queries
- Count how many employees executed each number of unique queries
- Sort results by query count in ascending order
Output columns: unique_queries, employee_count
Examples
Example 1:
Output:
Input:
| employees | |
|---|---|
| employee_id | employee_name |
| 101 | Alice |
| 102 | Bob |
| 103 | Charlie |
| queries | |||
|---|---|---|---|
| employee_id | execution_date | query_id | query_text |
| 101 | 2023-07-15 10:00:00 | 1 | SELECT * FROM users |
| 101 | 2023-08-20 11:00:00 | 2 | SELECT * FROM orders |
| 102 | 2023-09-10 12:00:00 | 3 | SELECT * FROM products |
| employee_count | unique_queries |
|---|---|
| 1 | 0 |
| 1 | 1 |
| 1 | 2 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
IBM