shlogg · Early preview
Judy @esproc_spl

Cumulative Discount Calculation For Customers Based On Orders

We have two database tables: ORDERINFO & TIER. We need to query TIER based on ORDERINFO to find cumulative discounts for each customer. Here's a SPL script p1.dfx that solves this problem.

Problem description & analysis
We have two database table. One is ORDERINFO, which has data as follows:

The other is TIER, which stores data as follows:

In the order information table (ORDERINFO), each customer (CUST) corresponds to N orders (ORDERS). According to the number of orders in ORDERINFO, we are trying to query the cumulative discount table (TIER) to find how many times each customer can get the discount privilege for their number of orders and record the discount in each time. Below is the desired result:

Solution
We write the following SPL script p1.dfx within esProc:

Explanati...