Professional Documents
Culture Documents
OLAP Operations
OLAP Operations
OLAP Operations
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:
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: