Mining historical data can help in discovering actionable knowledge. However, mining activities cannot be done directly on the regular databases. In order to perform data mining, it is required to prepare datasets that will be useful for mining process. Preparing datasets manually for data mining is a challenging task as it needs aggregations, complex SQL queries. The problem with existing aggregate functions of SQL such as SUM, MAX, MIN, COUNT and AVG return a single value as output. Such scalar value cannot be used for preparing datasets.