3.3 Get union of two sets
The union of set A and set B is made up of members that are in set A or in set B. For instance, the union of [1,2] and [1,3] is [1,2,3]. Note that their common member 1 only appears once in the union.
Here is an example. A business has two sales channels – online and offline stores. Their sales data is stored in SALES_ONLINE table and SALES_STORE table respectively. The task is to get products whose online cumulative sales amount is above 10000 or that are purchased more than 5 times offline in the year 2014. Below is part of data in the two tables:
SPL can use character “&” to calculate union of sets. A&B, for instance, calculates union of set A and set B.
A1: Import SALES_ONLINE table from the original file and select sales records of the year 2014.
A2: Import SALES_STORE table from the original file and select sales records of the year 2014.
A3: Group A1 by PRORDUCTID and calculate the total sales amount for each product in the online store, and select records where the total amount exceeds 10000.
A4: Group A2 by PRORDUCTID and calculate the total sales amount for each product in the offline store, and select records where the product is purchased more than 5 times.
A5: Use operator “&” to calculate the union of A3 and A4.