Row-to-Column Transposition

Question

Here is the original SQL:

select day,registerCount,loginCount

from(

select day from date where day between 20120101 and 20120103)tmp

left join(

select registerCount from register)r on tmp.day=r.day

left join(

select loginCount from login)l on tmp.day=l.day

group by day;

This is the result set:

undefined

Now I want a result set in the form like this:

undefined

But I don’t know how to do this, is there any help?

 

Answer

A

1

$select   day,registerCount,loginCount from…

2

=A1.pivot@r(day;type,count)

3

=A2.pivot(type;day,count)

A1: The original SQL query;

A2: Rotate column values in A1 to row values and the column headings registerCount and loginCount to the column values under type. Here’s the result set:

undefined

A3: Perform row-to-column transposition over A2 to rotate distinct values under day field into new field names.

undefined

The SPL script can be integrated with another application via esProc JDBC. For details, see .