I have a table called work which has columns as:
CREATE TABLE work (user text, user_type text, medium text,
docs_read int, on_date timestamp with timezone);
I want to create buckets(0-99, 100-199, etc) of number of documents read per day and calculate average, min and max productivity of each combination of user_type and medium across days.
I can calculate sum of docs_read and group by on_date to get number of docs_read per day using:
SELECT on_date::date as day, sum(docs_read) as total_docs_read
FROM work GROUP BY day;
Now, I have to group total_docs_read per day into buckets of size 100 and calculate average, min and max of productivity of each user_type and medium for each of those buckets.
Productivity = sum of docs_read in a day/ number of users working that day
Basically we have different types of users like Prof, Asst Prof etc reading docs in different languages and we want to know how many docs they read per day per user. So for each work-load bucket, each user_type and medium, I want to get average, max and min of average productivity per day over multiple days that fall within a bucket.
Sample output should be:
docs_read_bucket user_type medium avg_prod max_prod min_prod
0-99 A English 30 50 15