Help Guide on OLAP Operations

This section includes examples of some of the common OLAP operations you can perform on the OLAP database using ZCQL.

Example Database:

Given below is a sample table that contains the sales data of products by region, year, and quarter.

sale_id region product year quarter amount
101 East Laptop 2024 Q1 900
102 East Laptop 2024 Q2 1100
103 East Phone 2024 Q1 500
104 West Laptop 2024 Q1 800
105 West Phone 2024 Q2 600
106 West Laptop 2024 Q2 700
107 North Phone 2024 Q1 300
108 North Phone 2024 Q2 400

Roll-Up

Roll-up involves aggregating or summarizing the data to a higher-level hierarchy, reducing granularity. For example, summarizing the data from quarter to year, or from individual sales amount to a total.

This example query will roll up from a quarter-level sales to a yearly sales total, per region.

copy
SELECT region, year, Sum(amount) FROM sales_fact GROUP BY region, year ORDER BY region

It will generate the following output:

region year Sum(amount)
East 2024 2500
North 2024 700
West 2024 2100

Drill-Down

The drill-down operation moves down from a summary-level to a lower level in the concept hierarchy, providing a more detailed view of the data and adding new dimensions.

This example query will drill down and provide totals for each quarter, instead of yearly totals.

copy
SELECT region, year, quarter, Sum(amount) FROM sales_fact GROUP BY region, year, quarter ORDER BY region, quarter

It will generate the following output:

region year quarter Sum(amount)
East 2024 Q1 1400
East 2024 Q2 1100
North 2024 Q1 300
North 2024 Q2 400
West 2024 Q1 800
West 2024 Q2 1300

Slicing

The Slice operation selects a single dimension from the cube where data is represented, and creates a slice of the cube with reduced dimensionality. This operation helps focus on a specific data slice for analysis.

This example query will provide the average Q1 sales amount per region.

copy
SELECT region, Avg(amount) FROM sales_fact WHERE quarter = 'Q1' GROUP BY region ORDER BY region

It will generate the following output:

region Avg(amount)
East 700
North 300
West 600

Dicing

The Dice operation applies multiple filters on two or more dimensions of the cube where the data is represented, to form a smaller sub-cube. It provides a multidimensional subset of the original data cube.

This example query will count the number of Laptop sales in the East and West regions during Q1 or Q2 of 2024.

copy
SELECT region, Count(sale_id) FROM sales_fact WHERE product = 'Laptop' AND region IN ('East', 'West') AND quarter IN ('Q1', 'Q2') AND year = 2024 GROUP BY region ORDER BY region

It will generate the following output:

region Count(sale_id)
East 2
West 2

Last Updated 2026-02-16 20:32:46 +0530 IST