OLAP Operations

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

OLAP Operations

1.Roll-up : Aggregating data from a lower level of granularity to a higher level.


Question: Roll up the data from individual rooms to calculate the total occupancy for
each hotel on date:

Query:
SELECT hotel_id, date, SUM(number_of_occupied_rooms) AS total_occupied
FROM fact_JUI
GROUP BY hotel_id, date
ORDER BY hotel_id, date;

Output:

2. Drill-down: Breaking down aggregated data into finer levels of granularity.


Question : Monthly to daily occupancy data for a specific hotel and room.

Query:
SELECT *
FROM fact_jui
WHERE hotel_id = 3 AND room_id = 222 AND EXTRACT(YEAR FROM date) =
2003 AND EXTRACT(MONTH FROM date) = 4;

Output:
3. Slice: It selects a single dimension from the OLAP cube which results in a new sub-cube
Question: Get the occupancy details for a specific hotel and date.

Query:
SELECT *
FROM fact_JUI
WHERE hotel_id = 1 AND date = '2000-12-02';

Query:
SELECT * FROM Fact_placement
WHERE company_id = 1; -- Slicing by company_id

Output:

4. Dice: Selects a sub-cube from the OLAP cube by selecting two or more dimensions
Question: Get the occupancy details for a specific hotel, room, and date.
Query:
SELECT *
FROM fact_JUI
WHERE hotel_id = 2 AND room_id = 234 AND date = '2014-01-20';
Output:

5. Pivot: It rotates the current view to get a new view of the representation
Question: Compare the occupancy of different hotels on a specific date
Query:
SELECT hotel_id,
SUM(CASE WHEN date = '2020-11-22' THEN number_of_occupied_rooms ELSE 0
END) AS OccupiedRooms,
SUM(CASE WHEN date = '2020-11-22' THEN number_of_vacant_rooms ELSE 0
END) AS VacantRooms
FROM fact_JUI
GROUP BY hotel_id;

Output:

You might also like