Back to questions

IBM db2 Product Analytics IBM SQL Interview Question

IBM db2 Product Analytics

IBM SQL Interview Question

IBM is analyzing how their employees are utilizing the Db2 database by tracking the SQL queries executed by their employees. The objective is to generate data to populate a histogram that shows the number of unique queries run by employees during the third quarter of 2023 (July to September). Additionally, it should count the number of employees who did not run any queries during this period.

Display the number of unique queries as histogram categories, along with the count of employees who executed that number of unique queries.

Schema:

Column NameTypeDescription
employee_idintegerThe ID of the employee who executed the query.
query_idintegerThe unique identifier for each query (Primary Key).
query_starttimedatetimeThe timestamp when the query started.
execution_timeintegerThe duration of the query execution in seconds.

Example Input:

Assume that the table below displays all queries made from July 1, 2023 to 31 July, 2023:

employee_idquery_idquery_starttimeexecution_time
22685698707/01/2023 01:04:432698
13228611507/01/2023 03:25:122705
2213368307/01/2023 04:34:3891
2401774507/01/2023 14:33:472093
11041347707/02/2023 10:55:14470

Schema:

Assume that the table below displays all employees in the table:

Column NameTypeDescription
employee_idintegerThe ID of the employee who executed the query.
full_namestringThe full name of the employee.
genderstringThe gender of the employee.

Example Input:

employee_idfull_namegender
1Judas BeardonMale
2Lainey FranciottiFemale
3Ashbey StrahanMale

Example Output:

unique_queriesemployee_count
0191
146
212
31

The output indicates that 191 employees did not run any queries, 46 employees ran exactly 1 unique queries, 12 employees ran 2 unique queries, and so on.

The dataset you are querying against may have different input & output - this is just an example!

Input

(PostgreSQL)

Output