OLTP: | OLAP: |
Data changes often | Data is static |
Current data stored | Stores historic data |
Few indexes | Many indexes to speed up complex queries |
Fast and optimized | Accurate and complete |
Highly normalized | Highly denormalized |
SELECT RANK(45500, .05) WITHIN GROUP
(ORDER BY salary, commission_pct) "Rank"
FROM employees;
Rank
----------
55
As an analytic function, RANK computes the rank of each row returned from a query with respect to the other rows returned by the query, based on the values of the value_expression in the order_by_clause. Here is an example of an analytical RANK:(ORDER BY salary, commission_pct) "Rank"
FROM employees;
Rank
----------
55
SELECT department_id, last_name, salary, commission_pct,
RANK() OVER (PARTITION BY department_id
ORDER BY salary DESC, commission_pct) "Rank"
FROM employees WHERE department_id = 80;
DEPARTMENT_ID | LAST_NAME | SALARY | COMMISSION_PCT | Rank |
80 | Brown | 14000 | .4 | 1 |
80 | Lewis | 13500 | .3 | 2 |
80 | Smith | 12000 | .3 | 3 |
80 | Carlson | 11500 | .25 | 4 |
80 | Chambers | 11000 | .3 | 5 |
80 | Adams | 11000 | .3 | 5 |
The following example computes the ranking of a hypothetical employee with the salary $45,500 and a commission of 5%.
SELECT DENSE_RANK(45500, .05) WITHIN GROUP
(ORDER BY salary DESC, commission_pct) "Dense Rank"
FROM employees;
Dense Rank
-------------------
3
There it is the OLAP RANK SQL. I'll discuss other OLAP SQL functions in future posts.
(ORDER BY salary DESC, commission_pct) "Dense Rank"
FROM employees;
Dense Rank
-------------------
3
No comments:
Post a Comment