Oracle SQL how to group by first and then compare frequency -
i have table looks like
table operation employee '<' id1 '<' id1 '<' id2 '*' id3 '/' id1 for each operation, want know employee most? employee 2nd?
try this:
select operations.operation, employees.employee, employees.rank ( select t1.operation table t1 group t1.operation ) operations inner join ( select t2.employee, t2.operation, count(1) rank table t2 group t2.employee ) employees on operations.operation = employees.operation order operations.operation, employees.rank desc for every operation, getting count of each corresponding employee. operations distinct due group by in subquery , employees distinct due group by in other subquery. join 2 subqueries on operation , sort number of times each employee associated operation.
Comments
Post a Comment