I have a project I am working on that requires the following :
What does OLAP query mean? I've searched the internet and all that I can find is that I have to make a cube, and apply queries on it. How can I write an OLAP query on a RDBMS? I have a sample : tables normalized(orders,product,customer,branch,sales)
I want to write an OLAP query on the above tables. I am using Oracle Express with SQL Developer.
There are some SQL functions that are sometimes called "analytic", "windowing", or "OLAP", depending on the RDBMS you are using. In some scenarios they can provide enormous performance improvements, typically where you are comparing rows within the same set of data, which would otherwise require a self-join.
As you are using Oracle I would heartily recommend visiting asktom.oracle.com and searching for "analytics rock" - you will find some great examples, which are very well explained and much easier than just reading the Oracle documentation, which is here.
Some notes: they are not strictly "relational", because relational theory does not address the order of tuples; they are carried out after the other parts of a query - i.e. after filtering and aggregation; and they are implemented to a lesser extent by some databases.
I see that Oracle also have a separate OLAP offering for working with cubes, but this is currently a separately licensed option for Enterprise Edition, so I don't think it is what you are referring to if you are using Express edition.
EDIT
Here's a simple example roughly based on your data model that shows how you can use analytic functions to get a running total, which is not simple to do without them:-
select
o.customerid,
o.orderid,
o.orderdate,
p.price,
sum (p.price) over (partition by o.customerid order by o.orderdate) running_total
from orders o
inner join sales s on o.orderid = s.orderid
inner join product p on s.productid = p.productid
This gives (for some simple data I inputted):-
CUSTOMERID ORDERID ORDERDATE PRICE RUNNING_TOTAL
-------------------- -------------------- --------- ----- -------------
1 1 01-JAN-12 30 30
1 2 01-MAR-12 30 60
1 3 01-APR-12 30 90
1 4 01-MAY-12 30 120
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With