* How to implement a pivot without aggregation?

Key words:   pivot   without aggregation

The latest version of the mainstream database provides pivot function, which is more convenient to handle some static row and column transpose queries. However, because it is bundled with aggregation operation, it will cause some understanding problems. See the following example:

CustomerID DBColumnName Data
1 FirstName Joe
1 MiddleName S
1 LastName Smith
1 Date 12/12/2009
2 FirstName Sam
2 MiddleName S
2 LastName Freddrick
2 Date 1/12/2009
3 FirstName Jaime
3 MiddleName S
3 LastName Carol
3 Date 12/1/2009

Need to be transposed to

CustomerID FirstName MiddleName LastName Date
1 Joe S Smith 12/12/2009
2 Sam S Freddrick 1/12/2009
3 Jaime S Carol 12/1/2009

This is a simple transpose operation without aggregation, but when using pivot in SQL, you have to aggregate it with Max / min. Although the action is not big, it does cause difficulties for novices to understand. If you don’t have a deep understanding of pivot and unpivot, you often misunderstand them as reciprocal operations. In fact, it is not because the aggregation of binding is irreversible (the detailed data can sum, but the sum cannot calculate the detailed data).

 

If the SPL language which advocates step-by-step calculation is used, there will be no such misunderstanding. The pivot in SPL is designed as a pure transpose action, which is simple to write and understand:

=connect(”mysqlDB”).query(“select * from t”).pivot(CustomerID; DBColumnName, Data)

 In addition to the static transposition with clear data structure, there are complex transposition requirements such as dynamic transposition with unknown data structure, bidirectional transposition and transposition with inter column operation. These calculations are easy to write with SPL. Refer to Transposition.


When the data is not in the database, it is still convenient for SPL to perform complex calculations:

=file(“d:/t.csv”).import(;,",")...

It's also easy to embed esProc into Java applicationsplease refer to How to Call an SPL Script in Java

For specific usage, please refer to  Getting started with esProc