tag:blogger.com,1999:blog-1055414601554707802024-03-14T09:19:43.349-05:00esProc, A Script Language for Data Analytics with Parallel MechanismConcise,Convenient, EfficentAnonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.comBlogger332125tag:blogger.com,1999:blog-105541460155470780.post-54880381476448921022016-05-08T18:42:00.003-05:002016-05-08T18:46:25.046-05:00Dynamic Criterion in Report Building<div class="T-ParCxSpFirst" style="text-align: center; text-indent: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="text-indent: 0cm;"><span style="font-family: inherit;">You can perform data sorting in
both the report script and in SQL. But both are only capable of sorting data by
specified field(s). To sort data by a specified list, you have to compose the
code using functions like decode and union. If the sorting criterion is a
dynamic parameter, it’s more difficult to implement it in SQL or with a report
script as a temporary table is usually needed. What’s worse, the sorting
criterion doesn’t always correspond to the field values completely. Sometimes
you need to fill in the difference, while other times you can just ignore them.
It’s rather complicated in handling both issues.</span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="font-family: inherit;"><span lang="EN-US">With support of alignment
functions, order-related computations and explicit sets, esProc can easily
solve the sorting problems mentioned above. So you can use it as the tool for
report data source preparation. </span><span lang="EN-US">The reporting tool
regards an esProc script as the stored procedure, passes parameter to it and
gets the returned result after execution through JDBC. For more details, see <b><i><a href="http://blog.raqsoft.com/?p=4665" target="_blank">Howto Use esProc to Assist Reporting Tools</a></i></b></span><span lang="EN-US">. </span><span lang="EN-US"><o:p></o:p></span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">Here are the sorting problems concerning external/dynamic
criterion commonly seen in report development, and their solutions in esProc.</span><span lang="EN-US"> <o:p></o:p></span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: small;">Sorting by
simple external criterion</span></span></h3>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Sort the <i>Service</i> table according to the condition that the <i>aNum</i> field will be presented in an order
specified by [1,3,2,4], as shown by selections of source and target tables below:<o:p></o:p></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; margin-left: 33.75pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 163.05pt;" valign="top" width="217"><div align="center" class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Source
table <o:p></o:p></span></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 155.9pt;" valign="top" width="208"><div align="center" class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Target
table<o:p></o:p></span></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 163.05pt;" valign="top" width="217"><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 144px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">aNum<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">z<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">n<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">t<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">t<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">w<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">e<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 7;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">a<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 8;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">r<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 9;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">q<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 10;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">q<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 11; mso-yfti-lastrow: yes;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">y<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><o:p></o:p></span></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 155.9pt;" valign="top" width="208"><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 144px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">aNum<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">t<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">t<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">z<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">n<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">w<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">e<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 7;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">a<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 8;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">q<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 9;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">y<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 10;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">r<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 11; mso-yfti-lastrow: yes;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">q<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">esProc code:<o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-insideh: .5pt solid #A6A6A6; mso-border-insidev: .5pt solid #A6A6A6; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-table-layout-alt: fixed; width: 294px;">
<tbody>
<tr>
<td style="background: #BFBFBF; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
</td>
<td style="background: #BFBFBF; border-left: none; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 206.2pt;" valign="top" width="275"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">A<o:p></o:p></span></span></span></div>
</td>
</tr>
<tr>
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 206.2pt;" valign="top" width="275"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">$select
name,aNum from tb<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 206.2pt;" valign="top" width="275"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=A1.align@a([1,3,2,4],aNum).conj()<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">A1 performs a SQL statement. The <i>align</i> function groups and sorts records
according to the specified list, with the default rule that only the first
found record is retained; but with @a, the function will retrieve all records
in a group. The <i>conj</i> function
concatenates records together.</span></span></div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="text-indent: -18pt;"><span style="font-family: inherit;"><br /></span></span></div>
<div class="T-ParCxSpFirst" style="text-indent: 0px;">
<span style="font-family: inherit;"><span style="text-indent: -18pt;">1. Dynamic
sorts can be achieved through a parameter, such as </span><span style="color: #002060; text-indent: -18pt;">A2=A1.align@a(arg_List,
aNum).conj()</span><span style="text-indent: -18pt;">. So when arg_List is [1,3,2,4], we can get our result. In
this way the code becomes reusable.</span></span></div>
<div class="T-ParCxSpFirst" style="text-indent: 0px;">
<span style="text-indent: -18pt;"><span style="font-family: inherit;"><br /></span></span></div>
<div class="T-ParCxSpFirst" style="text-indent: 0px;">
<span style="font-family: inherit;"><span style="text-indent: -18pt;">2. If
there are fewer items in the list than the </span><i style="text-indent: -18pt;">aNum</i><span style="text-indent: -18pt;">
field values, such as arg_List=[1,2,4], records that don’t have matching items
will be discarded by default, as shown by the following result:</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnA-FGNMT0qpOrSC8FyA3C1yATLFBBDXpjGQqyG4uPujCfjRCnIJu9QsfrHyzTuWhhEoeUCrDkoQB1mu2jko8fcUZ0uCkFekL7T6pCWjb_XSnEojjI8Qj4cRR4hWyHIgIZrF1P5IZ5Rm0/s1600/2016-05-09_073457.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnA-FGNMT0qpOrSC8FyA3C1yATLFBBDXpjGQqyG4uPujCfjRCnIJu9QsfrHyzTuWhhEoeUCrDkoQB1mu2jko8fcUZ0uCkFekL7T6pCWjb_XSnEojjI8Qj4cRR4hWyHIgIZrF1P5IZ5Rm0/s320/2016-05-09_073457.jpg" width="320" /></a></div>
<div class="T-ParCxSpFirst" style="text-indent: 0px;">
<span style="text-indent: -18pt;"><span style="font-family: inherit;"><br /></span></span></div>
<div align="center" class="T-ParCxSpMiddle" style="margin-left: 39.0pt; mso-add-space: auto; mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span style="font-family: inherit;"><span lang="EN-US"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="_x0000_i1028" style="height: 118.5pt; mso-wrap-style: square; visibility: visible; width: 3in;" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///C:\Users\ADMINI~1.USE\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-align: justify; text-indent: 0cm; text-justify: inter-ideograph;">
<span lang="EN-US"><span style="font-family: inherit;">To append those mismatched records after the sorted ones, use <span style="color: #002060;">A2=A1.align@n(arg_List, aNum).conj()</span> and the
result is as follows: <o:p></o:p></span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-align: justify; text-indent: 0cm; text-justify: inter-ideograph;">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-align: justify; text-indent: 0cm; text-justify: inter-ideograph;">
<span lang="EN-US"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM2z27jxAtBsv7CoD_kVBhUWoXzdeB4fU4Vcw6FKpYaUOXa9nv4oi9HX3GuMfku_xlP7EjOnxHUgljK8O5BjDV6-yr_h8ZFbVDpMdqzUt-mGU579y1FX3371bt-BNSnn8tjBUKA90VbDI/s1600/2016-05-09_073505.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM2z27jxAtBsv7CoD_kVBhUWoXzdeB4fU4Vcw6FKpYaUOXa9nv4oi9HX3GuMfku_xlP7EjOnxHUgljK8O5BjDV6-yr_h8ZFbVDpMdqzUt-mGU579y1FX3371bt-BNSnn8tjBUKA90VbDI/s320/2016-05-09_073505.jpg" width="320" /></a></span></div>
<div align="center" class="T-ParCxSpMiddle" style="margin-left: 39.0pt; mso-add-space: auto; mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span style="font-family: inherit;"><span lang="EN-US"><v:shape id="图片_x0020_3" o:spid="_x0000_i1027" style="height: 178.5pt; mso-wrap-style: square; visibility: visible; width: 213.75pt;" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///C:\Users\ADMINI~1.USE\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Or you can use the equal statement
- <span style="color: #002060;">A2=A1.align@s(arg_List, aNum)</span>.</span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="text-indent: -18pt;"><span style="font-family: inherit;"><br /></span></span></div>
<div class="T-ParCxSpMiddle" style="text-indent: 0px;">
<span style="text-indent: -18pt;"><span style="font-family: inherit;">3. If
the items of the list outnumber the field values, the extra items won’t appear
in the sorting result.</span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: small;">Exporting data in specified order </span></span></h3>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="text-indent: 0cm;"><span style="font-family: inherit;">Suppose we need to sort the
database table PRODUCT for presentation. Instead of performing the sort by a
field, the requirement is that the top N records be sorted in the specified
order and the rest by an existing field, as shown in the following selections
of source table and target table:</span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 213.05pt;" valign="top" width="284"><div align="center" class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Source
table<o:p></o:p></span></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 213.05pt;" valign="top" width="284"><div align="center" class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-align: center; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Sort
the top 4 records in specified order<o:p></o:p></span></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 213.05pt;" valign="top" width="284"><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 144px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">PRODUCT_ID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">PRODUCT_NAME<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">100<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Nokia<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">200<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">IPhone<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">300<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Samsung<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">400<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">LG<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">500<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">HTC<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">600<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">BlackBerry<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><o:p></o:p></span></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 213.05pt;" valign="top" width="284"><table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 190px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">PRODUCT_ID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">PRODUCT_NAME<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">300<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Samsung<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">400<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">IPhone<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">100<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Nokia<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">200<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">LG<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">500<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">HTC<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">600<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 76.8pt;" width="102"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">BlackBerry<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">esProc code:<o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-insideh: .5pt solid #A6A6A6; mso-border-insidev: .5pt solid #A6A6A6; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-table-layout-alt: fixed; width: 357px;">
<tbody>
<tr>
<td style="background: #BFBFBF; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
</td>
<td style="background: #BFBFBF; border-left: none; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 253.6pt;" valign="top" width="338"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">A<o:p></o:p></span></span></span></div>
</td>
</tr>
<tr>
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 253.6pt;" valign="top" width="338"><div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">$select
</span><span lang="EN-US">PRODUCT_ID,
PRODUCT_NAME from </span><span lang="EN-US">PRODUCT<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 253.6pt;" valign="top" width="338"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=A1.align@s(arg_IDList,
PRODUCT_ID)<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="font-family: inherit;"><span lang="EN-US">The <i>align</i> groups and sorts data according to the specified list, and @s
adds the mismatched records at the end. The above target table can be obtained
when arg_IDList is [300,400,100,200].</span><span style="text-indent: 21pt;"> </span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: small;">Finding missing values </span></span></h3>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">There are a lot of records in <i>Table1</i> where ID field is a sequence
consisting of inconsecutive integers. Now we need to find those missing
integers and put them in the right places in <i>Table1</i>, while leaving corresponding fields in blank. Below is a
selection of the source data: <o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 216px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">ID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Amount<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1001<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Jonathan<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">4418.6<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1002<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Timothy<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3212.7<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1003<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Michael<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2711.3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1007<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Alexis<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">5322.4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1008<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">832<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1009<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Daniel<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">3423.3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 7;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1010<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Joseph<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">483.2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1012<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Chloe<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">87332.2<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">If the set of integers is small, we
can generate a sequence with consecutive numbers in SQL with the minimum and
the maximum values, compute the difference between this sequence and the ID
field values using a subquery, then create empty records and union with the
original data, and finally perform a sort. But if the set is big, we need to look
for a workaround for implementing the merge algorithm to increase the
performance. As a result, the code becomes complicated. esProc supports a
direct merge by fields, and thus can produce the following code: <o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-insideh: .5pt solid #A6A6A6; mso-border-insidev: .5pt solid #A6A6A6; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-table-layout-alt: fixed; width: 329px;">
<tbody>
<tr>
<td style="background: #BFBFBF; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 0cm 0cm 0cm; width: 232.3pt;" valign="top" width="310"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=db.query(“select
ID from table1 order by ID”)<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 1;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 232.3pt;" valign="top" width="310"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=to(A1.m(1).ID,A1.m(-1).ID).new(~:ID,Name,Amount)<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 232.3pt;" valign="top" width="310"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=[A1,A2].merge@u(ID)
<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">The <i>m</i> function can get members of a set by their sequence numbers in
both normal and reverse orders. A1.m(1) an be simplified as A1(1). The <i>to</i> function generates a consecutive
sequence. The <i>merge</i> function merges
ordered data, and it works with @u to get the union. Here’s the result: <o:p></o:p></span></span></div>
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNv8kAWEDPtSH96MN8vLUJjxiN1b8ihK3-FvHI0b7ieN-Ou4hOboyhKMVtIH08yi9wMbE_VOV6DAjs48pReY4pY1_cy-9h3fVX17F8DKUtXdhgA25Nwh4hgPJfuaJhAQUjWQCWCZgr388/s1600/2016-05-09_073520.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="271" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNv8kAWEDPtSH96MN8vLUJjxiN1b8ihK3-FvHI0b7ieN-Ou4hOboyhKMVtIH08yi9wMbE_VOV6DAjs48pReY4pY1_cy-9h3fVX17F8DKUtXdhgA25Nwh4hgPJfuaJhAQUjWQCWCZgr388/s320/2016-05-09_073520.jpg" width="320" /></a></span></div>
<div align="center" class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-align: center; text-indent: 21.0pt;">
<span style="font-family: inherit;"><span lang="EN-US"><v:shape id="图片_x0020_1" o:spid="_x0000_i1026" style="height: 193.5pt; mso-wrap-style: square; visibility: visible; width: 229.5pt;" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///C:\Users\ADMINI~1.USE\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span lang="EN-US"><o:p></o:p></span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: small;">Intra-group sorting in a fixed order</span></span></h3>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">The <i>attendance</i> table records the attendance
information. The requirement is to convert each person’s information per day (a
fixed 7 records) to two rows - one is morning and the other is afternoon for
reporting. For each row, <i>Per_Code</i>, <i>Date</i>, <i>In</i> and <i>Out</i> fields are the
same but <i>Break</i> and <i>Return</i> fields are not. Below is the attendance
information of a person on a certain day: <o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 438px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Per_Code<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">in_out<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Date<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Time<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Type<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">17:14.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">In<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">6<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">37:00.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Break<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">5<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">38:21.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Return<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">43:21.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">NULL<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">6<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">21:30.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Break<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">5<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">25:58.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Return<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 7; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">1110263<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 88.95pt;" width="119"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">2013-10-11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 77.05pt;" width="103"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">28:55.0<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Out<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">According to
this data, we should retrieve the 4 records of the morning by the specified
sequence numbers and then transform them to a single record with static method.
The operation will be performed on records of both morning and afternoon
separately. There are a lot of real world cases that involve this kind of
order-related algorithm. But as SQL lacks the intrinsic sequence numbers, it
turns to <i>pivot</i> and <i>over</i> methods or the like. The problem is
the composed code is difficult to understand and debug. <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">esProc code: <o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-insideh: .5pt solid #A6A6A6; mso-border-insidev: .5pt solid #A6A6A6; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-table-layout-alt: fixed; width: 606px;">
<tbody>
<tr>
<td style="background: #BFBFBF; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
</td>
<td style="background: #BFBFBF; border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="center" class="MsoNormal" style="line-height: 150%; text-align: center;">
<span style="font-family: inherit;"><span class="code"><span lang="EN-US" style="line-height: 150%; mso-bidi-font-size: 10.5pt;">A</span></span><span class="code"><span lang="EN-US" style="line-height: 150%;"><o:p></o:p></span></span></span></div>
</td>
</tr>
<tr>
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">1<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=$select
* from attendance order by Per_Code,Date,Time <o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 2;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">2<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=A1.group(Per_Code,Date)<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 3;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">3<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=A2.(~.align([1,7,2,3],#))<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 4;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">4<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=AM=A3.new(Per_Code,
Date, ~.(Time)(1):In ,~.(Time)(2):Out, ~.(Time)(3):Break, ~.(Time)(4):Return)<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 5;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">5<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=A2.(~.align([1,7,5,6],#))<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 6;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">6<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=PM=A5.new(Per_Code,
Date, ~.(Time)(1):In ,~.(Time)(2):Out, ~.(Time)(3):Break, ~.(Time)(4):Return)<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 5.25pt; mso-yfti-irow: 7; mso-yfti-lastrow: yes;">
<td style="background: #BFBFBF; border-top: none; border: solid #A6A6A6 1.0pt; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 14.2pt;" valign="top" width="19"><div align="center" class="MsoNormal" style="text-align: center;">
<span class="code"><span lang="EN-US"><span style="font-family: inherit;">7<o:p></o:p></span></span></span></div>
</td>
<td style="border-bottom: solid #A6A6A6 1.0pt; border-left: none; border-right: solid #A6A6A6 1.0pt; border-top: none; height: 5.25pt; mso-border-alt: solid #A6A6A6 .5pt; mso-border-left-alt: solid #A6A6A6 .5pt; mso-border-top-alt: solid #A6A6A6 .5pt; padding: 0cm 0cm 0cm 0cm; width: 440.5pt;" valign="top" width="587"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">=AM |
PM<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">A3 retrieves
record 1, 7, 2 and 3 from each group. A4 joins and converts the four records
into a single record and stores it in the empty two-dimensional table sequence
AM. ~ represents the current group, </span><span lang="EN-US"># </span><span lang="EN-US">represents a sequence number in a group, and | concatenates
records together.</span></span></div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<span style="font-family: inherit;"><span lang="EN-US"><v:shape id="图片_x0020_8" o:spid="_x0000_i1025" style="height: 45.75pt; mso-wrap-style: square; visibility: visible; width: 339pt;" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///C:\Users\ADMINI~1.USE\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png">
</v:imagedata></v:shape></span><span lang="EN-US"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Here’s the
result for a person on a certain day: </span><span style="font-family: "times new roman" , serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3IW8QvPrZvouK0BtFwx3He5wps36SN4pBv04gzFa2mTIQvSlSFo9p93TYJbYy7kPV_Fh-G6lu1UmPlBGGTk50nrBbmbYmGzskg4wDfIvv7ixyNDHoLjzyEntZfWZ-POFMYT2kC6ZGTu8/s1600/2016-05-09_073529.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3IW8QvPrZvouK0BtFwx3He5wps36SN4pBv04gzFa2mTIQvSlSFo9p93TYJbYy7kPV_Fh-G6lu1UmPlBGGTk50nrBbmbYmGzskg4wDfIvv7ixyNDHoLjzyEntZfWZ-POFMYT2kC6ZGTu8/s1600/2016-05-09_073529.jpg" /></a></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-24287478547067446112016-04-07T19:21:00.003-05:002016-04-07T19:27:37.329-05:00The Standard Method of Performing Transposition <div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;">Sometimes the source data needs to be transposed before displaying
it in the report. But cross table can only handle the most basic transposition.
Most of the scenarios need to be dealt with using SQL, report script or Java
script. Each way has its own trick with high degree of difficulty. <o:p></o:p></span></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span style="font-family: inherit;"><span lang="EN-US">esProc supports dynamic scripting, order-related calculations and
set operations, and has the ability of realizing various types of data
transpositions using one universal method, that is, retrieving data, creating
empty result set and filling data in it. It is an ideal tool for report data
source preparation. The reporting tool regards an esProc script as the stored
procedure, passes parameter to it and gets the returned result after execution
through JDBC. You can learn more from <b><i><a href="http://blog.raqsoft.com/?p=4665" target="_blank">How to Use esProc to Assist Reporting Tools</a></i></b></span><span lang="EN-US">.</span><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">These are common transposition problems with
database tables in report development and their solutions using the standard
esProc method.</span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit;">Transposing
multiple columns to one row </span></span></h3>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">Below is the
format of the <i>Students</i> table: </span><span lang="EN-US"><o:p></o:p></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 288px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">age<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">sex<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">kg<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">10<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">f<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">30<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">B<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">f<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">35<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">C<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">12<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">m<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US"><span style="font-family: inherit;">33<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">You need to
combine all records into one row in a format and display it in the report as
shown below:<o:p></o:p></span></span><br />
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; text-align: center; width: 606px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 38.0pt;" width="51"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Aage<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Asex<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Akg<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Bage<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Bsex<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Bkg<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Cage<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Csex<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 38.35pt;" width="51"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Ckg<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 38.0pt;" width="51"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">10<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">f<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">30<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">f<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">35<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">12<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">m<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 38.35pt;" width="51"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">33<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">esProc
script:<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA4Bymi-3nzUfQ2-XHWnPdZn1ZpiKUvaI6F4q3sAchHxNaUDv_EP4zaClkn6dR-7BMfLOcVs4icPcDGByY79g8uy7QColpgKHqQd5lXHJWZMDKLxvVbZagVr8jHvfcT5ejQ4xe-SJedI0/s1600/esProc_report_transpose_report_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA4Bymi-3nzUfQ2-XHWnPdZn1ZpiKUvaI6F4q3sAchHxNaUDv_EP4zaClkn6dR-7BMfLOcVs4icPcDGByY79g8uy7QColpgKHqQd5lXHJWZMDKLxvVbZagVr8jHvfcT5ejQ4xe-SJedI0/s1600/esProc_report_transpose_report_1.jpg" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">A2 creates an
empty table sequence dynamically. A3 combines A1 into a single record and
appends it to A2.</span><span lang="EN-US"> ${} is used to parse a string into an
expression for dynamic execution. </span><span lang="EN-US" style="color: #002060;">string(field)</span><span lang="EN-US" style="color: #002060;"> </span><span lang="EN-US">means
converting data of other types into the string type data.</span><span lang="EN-US"> </span><span lang="EN-US" style="color: #002060;">set.string() </span><span lang="EN-US">means
concatenating members of a set into a string. The record function can be used
to append records. You can also append records with this line of code: </span><span lang="EN-US" style="color: #002060;">>A2.record(A1.conj(~.array().to(2,4)))<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">So
you can see that the standard method of performing transposition includes 3
steps: Retrieving data in SQL, creating an empty result set using create function,
and looping through the source data with run function and append new data to
the result set with record function. The code for data appending could vary
depending on different scenarios. <o:p></o:p></span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Multi-group
transposition</span></span></h3>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">In the database table <i>kpi</i>, every 4 records with the same f_site value is a group. You
need to create a group report based on different f_site values. Each group has
5 columns of detailed data - they are </span><span lang="EN-US">"KPI Name"</span>,<span lang="EN-US">"2015-04-21
13:15","2015-04-21 13:30","2015-04-21 13:45", and "2015-04-21
14:00".</span><span lang="EN-US"> </span><span lang="EN-US">The values of</span><span lang="EN-US"> </span><span lang="EN-US">KPI Name</span><span lang="EN-US"> are the three kpi columns - </span><span lang="EN-US">ioh_kpi, idh_kpi and
iol_kpi. The values of the four date fields are the kpi details of each time
period.</span><span lang="EN-US"> </span><span lang="EN-US">Below
is a selection from the source data:<o:p></o:p></span></span><br />
<span style="font-family: inherit;"><span lang="EN-US"><br /></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 5.4pt; text-align: center; width: 433px;">
<tbody>
<tr style="height: 14.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">dataset_date<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">f_site<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">ioh_kpi<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">idh_kpi<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">iol_kpi<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:15<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">X6SF_SARF1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:30<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">X6SF_SARF1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">9<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:45<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">X6SF_SARF1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">8<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">9<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 14:00<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">X6SF_SARF1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">7<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">8<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">9<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:15<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">XC_01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 6;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:30<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">XC_01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">12<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">13<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 7;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 13:45<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">XC_01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">21<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 14.0pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">22<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">23<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 14.0pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 14.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 105.0pt;" width="140"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015/04/21 14:00<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 72.2pt;" width="96"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">XC_01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">31<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 14.0pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">32<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 14.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 49.3pt;" width="66"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">33<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div align="left" class="MsoNormal" style="text-indent: 21pt;">
<br /></div>
<span style="font-family: inherit;"><span style="text-indent: 21pt;">esProc script:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTnJ-DIXkUl0cYB-GO2409CNGwThg61tvL2MIdeyKs5FmwdnDSKvbiId32KG4lcQ_JoQKp48s2SfCDQU-1Pe6udY-WKRp8QWH-y77sYMQM5G_90D9a_Oef3b_ROoLhk40JU3uRB5aQiVI/s1600/esProc_report_transpose_report_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTnJ-DIXkUl0cYB-GO2409CNGwThg61tvL2MIdeyKs5FmwdnDSKvbiId32KG4lcQ_JoQKp48s2SfCDQU-1Pe6udY-WKRp8QWH-y77sYMQM5G_90D9a_Oef3b_ROoLhk40JU3uRB5aQiVI/s1600/esProc_report_transpose_report_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><span lang="EN-US"><br /></span></span>
<span style="font-family: inherit;"><span lang="EN-US">A2 gets the distinct dataset_date values, that is ["2015-04-21
13:15","2015-04-21 13:30","2015-04-21
13:45","2015-04-21 14:00"]. B2 gets field names of A1 starting
from the third field, i.e. ["ioh_kpi","idh_kpi","iol_kpi"].
A3 creates a two-dimensional table dynamically, with field names being site,KPI
Name,"2015-04-21 13:15","2015-04-21 13:30","2015-04-21
13:45","2015-04-21 14:00". A4-B5 use a loop statement to append
data; the statement is equal to</span><span lang="EN-US"> </span><span lang="EN-US" style="color: #002060;">A1.group(f_site).run(…)</span><span lang="EN-US">, but it is more clear than run function when steps
are many. Here’s the result:</span> </span><br />
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJAaLZA8T5rjNvaLouAAJTIsmCswAS_Tz3JyfN-5BgjrqKQO2_M_D8TF3ABJm7kdvS_VchHYTqnEGGqPghLFLpKHaSCAg4n7Va19DfquCy5Gwe-DtepNqbDP6V9id-mxjt6-2gYgoRRkU/s1600/esProc_report_transpose_report_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJAaLZA8T5rjNvaLouAAJTIsmCswAS_Tz3JyfN-5BgjrqKQO2_M_D8TF3ABJm7kdvS_VchHYTqnEGGqPghLFLpKHaSCAg4n7Va19DfquCy5Gwe-DtepNqbDP6V9id-mxjt6-2gYgoRRkU/s1600/esProc_report_transpose_report_3.jpg" /></span></a></div>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span>
<span lang="EN-US"><span style="font-family: inherit;">Then you
just need to perform a group by site and then create a simple table for
reporting. <o:p></o:p></span></span></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Inverse
transposition</span></span></h3>
<span style="font-family: inherit;">A query finds
that the <i>tb1</i> table has one record
with many fields, as shown below: </span><br />
<span style="font-family: inherit;"><br /></span>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 33.75pt; text-align: center; width: 747px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 47.55pt;" valign="top" width="63"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">project<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">operator1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 68.55pt;" width="91"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">actionTime1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">operator2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 68.55pt;" width="91"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">actionTime2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 60.75pt;" width="81"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">operator3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 70.85pt;" width="94"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">actionTime3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">poerator4<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 69.55pt;" width="93"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">actionTime4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 47.55pt;" valign="top" width="63"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 68.55pt;" width="91"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">20140404<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Rachel<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 68.55pt;" width="91"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">20150101<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 60.75pt;" width="81"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Emily<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 70.85pt;" width="94"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">20140909<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 58.05pt;" width="77"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 69.55pt;" width="93"><div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">20150225<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span>
<span lang="EN-US"><span style="font-family: inherit;">You need to
create a report with three columns and multiple rows, as shown below:<o:p></o:p></span></span><br />
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 234px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" valign="top" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">project<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">operator<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">actionTime<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" valign="top" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">20140404<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" valign="top" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Rachel<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">20150101<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" valign="top" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Emily<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">20140909<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" valign="top" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.8pt;" width="88"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">20150225<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="separator" style="clear: both;">
</div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">esProc
script:<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: inherit;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGgJM_w02ZNMZ3jFgIj0RCHbB437hfHu53neRkCEoOcflDc8stlFSLJuM6VWVE1nCqvEx5e-vy0DBcDLloZwpEipFCDWUNRKZWck7-DL_u9pbiaYrcDDnkoycu2MdVsaz-xOosI9NheWQ/s1600/esProc_report_transpose_report_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGgJM_w02ZNMZ3jFgIj0RCHbB437hfHu53neRkCEoOcflDc8stlFSLJuM6VWVE1nCqvEx5e-vy0DBcDLloZwpEipFCDWUNRKZWck7-DL_u9pbiaYrcDDnkoycu2MdVsaz-xOosI9NheWQ/s1600/esProc_report_transpose_report_4.jpg" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">((A1.fno()-1)/2)
calculates the number of records that need to be added to the result set and
run function runs a loop to append them.</span><span lang="EN-US"> <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<span style="font-family: inherit;">If there is
more than one record in the <i>tb1</i> table
and each record has a different project, you need to use the following code: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhz4u_pr79VmZ36bI2PmC4xNQ6hNSYPfxckHSeyO81pilOhyLkILJmiXzC44y5cGn-k0fAaDxzxIr7LS4_3tbo1y0xVmt7gmmwY8eZoVYLvgvS0-BlUUUo9-MoKZgo0Cm6yJmlu5sA4Us/s1600/esProc_report_transpose_report_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhz4u_pr79VmZ36bI2PmC4xNQ6hNSYPfxckHSeyO81pilOhyLkILJmiXzC44y5cGn-k0fAaDxzxIr7LS4_3tbo1y0xVmt7gmmwY8eZoVYLvgvS0-BlUUUo9-MoKZgo0Cm6yJmlu5sA4Us/s1600/esProc_report_transpose_report_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Here’s the
result: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYaS3-cnNnhsvZGOYZSMmeeC7X6yKWPul8ik04Fy0ss0HWRU3yfMH2f07M4KfV8tJpv8gGh9FAZJgQMFWaQJJ_GUp7n0GePRa33fyWR0vR-HBCLSOZuHtUaW7BX6pK0FJEM3xU68Ghs9g/s1600/esProc_report_transpose_report_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYaS3-cnNnhsvZGOYZSMmeeC7X6yKWPul8ik04Fy0ss0HWRU3yfMH2f07M4KfV8tJpv8gGh9FAZJgQMFWaQJJ_GUp7n0GePRa33fyWR0vR-HBCLSOZuHtUaW7BX6pK0FJEM3xU68Ghs9g/s1600/esProc_report_transpose_report_6.jpg" /></span></a></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Inserting a subtable
with specified maximum length dynamically into the main table</span></span></h3>
<div class="MsoNormal">
<span style="font-family: inherit;"><i><span lang="EN-US">dColThread</span></i><span lang="EN-US"> and <i>dColQuestion</i>
are the main table and the subtable that are related through tID field. Each
record of the main table corresponds to multiple but less than 5 status field
values. You need to insert the status values between Phone and Decline fields
and name them QuestionNo1</span>、<span lang="EN-US">QuestionNo2…QuestionNo5. </span><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">Below is a
selection of <i>dColThread</i>:</span><span lang="EN-US"> <o:p></o:p></span></span><br />
<span style="font-family: inherit;"><span lang="EN-US"><br /></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 450px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="background: #C6D9F1; border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">tID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">ApplicationName<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">User<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Phone<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Decline<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mfc<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Bill<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">+70000000<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A02<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mfc<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">John<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">+18761221<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A03<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Jack<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">+8014001231<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">6<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A04<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mfc<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Tim<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">+008613133123<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A05<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 93.3pt;" width="124"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">db<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">John<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 82.3pt;" width="110"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">+18761221<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">8<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Below is a
selection of <i>dColQuestion</i>: <o:p></o:p></span></span><br />
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 216px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="background: #C6D9F1; border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">qID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">tID<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="background: #C6D9F1; border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-background-themecolor: text2; mso-background-themetint: 51; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">status<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">yes<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">no<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A01<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">yes<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">4<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A02<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">yes<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">5<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A03<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">no<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">6<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A04<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">no<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 7;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">7<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A04<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">no<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">8<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">A05<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">yes<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<span style="font-family: inherit;">esProc
script: </span><br />
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYN-yYS6oEvqT8uBH4WamgWi9xQiPEZEAqXSMkd6-rSDovw7Yp6NQW865q_oPeJZzbowKmybfUSpnxcaiY3aQqt1lPBpTd6fTH0yC3Ns0Q9dxSJWO3vjqZYJJxfePE3Wgbu-GNTg9SmVs/s1600/esProc_report_transpose_report_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYN-yYS6oEvqT8uBH4WamgWi9xQiPEZEAqXSMkd6-rSDovw7Yp6NQW865q_oPeJZzbowKmybfUSpnxcaiY3aQqt1lPBpTd6fTH0yC3Ns0Q9dxSJWO3vjqZYJJxfePE3Wgbu-GNTg9SmVs/s1600/esProc_report_transpose_report_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Create a
two-dimensional table with fixed fields in A3; loop through each of A2’s groups
to get the status value and complement the missing values to reach five; and
then append the complete records to A3.</span><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">A3 gets the
final result which can be displayed using the reporting tool’s table control
directly:<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYzCZJKSgY_E5AHTYgOq6kIqGuSmmJB_I_Zj0AUEH8tNdVlp8gXIHjveto8NfnTemN9we9TeDmScAX0I5eI353z-_ZuUm-jKW1PaIDdWF24nmavy47H89WpVRxcCohswRpRTEIEW5ZfR4/s1600/esProc_report_transpose_report_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYzCZJKSgY_E5AHTYgOq6kIqGuSmmJB_I_Zj0AUEH8tNdVlp8gXIHjveto8NfnTemN9we9TeDmScAX0I5eI353z-_ZuUm-jKW1PaIDdWF24nmavy47H89WpVRxcCohswRpRTEIEW5ZfR4/s1600/esProc_report_transpose_report_8.jpg" /></span></a></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Complementing
the missing months before transposition</span></span></h3>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">The <i>tb</i> table, with two fields - time and
quantity, contains the product’s sales quantity per day. In certain months, the
quantity value may be null. Below is a selection from the source data: <o:p></o:p></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; text-align: center; width: 360px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 140.0pt;" width="187"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">time<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 130.0pt;" width="173"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">quantity<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 140.0pt;" width="187"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2014-01-01 15:20:25<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 130.0pt;" width="173"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 140.0pt;" width="187"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2014-02-21 16:11:23<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 130.0pt;" width="173"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 140.0pt;" width="187"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015-01-05 11:14:21<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 130.0pt;" width="173"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 140.0pt;" width="187"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2015-02-11 15:21:11<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 130.0pt;" width="173"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">You need to present
12 rows in the grid of the report, with fields including the fixed months
(values are 1-12), and the annual sales quantity, as shown below:<o:p></o:p></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.5pt;" valign="top" width="142"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Month<o:p></o:p></span></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.5pt;" valign="top" width="142"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Quantity in 2013<o:p></o:p></span></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.55pt;" valign="top" width="142"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Quantity in 2014<o:p></o:p></span></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.55pt;" valign="top" width="142"><div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Quantity in …<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
<span style="font-family: inherit;">esProc
script: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzAXKI3B5ZYFQJ-zshyphenhyphen-ChGzE3kWooq3jjgseEyY0K7bNcFtCx0ADE0K6jIW216eLZc68n2pHiMcpkXUJd8N1_F_0zJcA4ze6sAfN3EfczV6WXb5LhU56_nmDqarxg6svBzYRgicGJL-s/s1600/esProc_report_transpose_report_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzAXKI3B5ZYFQJ-zshyphenhyphen-ChGzE3kWooq3jjgseEyY0K7bNcFtCx0ADE0K6jIW216eLZc68n2pHiMcpkXUJd8N1_F_0zJcA4ze6sAfN3EfczV6WXb5LhU56_nmDqarxg6svBzYRgicGJL-s/s1600/esProc_report_transpose_report_9.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">A1 performs a
SQL group and aggregate; A2 gets a list of years; A3 groups A1 according to the
sequence of 12 months; A4 dynamically creates an empty two-dimensional table;
A5 loops through every group of A3 and appends one record each time. Below is
the result of A3: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzeQQ0c9qhBAT_Kk98x_34TfHqjloNeTxDnzzisPAakI-xJ3KCYyPkOLMwu-8M7Ry-jLhlWuZR4BGXVpocYRjmOHYKc6xYmV3pmDhnj7QWCqcBt28bObadj3CChxMqvVnYL5u873PO8Ko/s1600/esProc_report_transpose_report_10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzeQQ0c9qhBAT_Kk98x_34TfHqjloNeTxDnzzisPAakI-xJ3KCYyPkOLMwu-8M7Ry-jLhlWuZR4BGXVpocYRjmOHYKc6xYmV3pmDhnj7QWCqcBt28bObadj3CChxMqvVnYL5u873PO8Ko/s1600/esProc_report_transpose_report_10.jpg" /></span></a></div>
<span style="font-family: inherit;">A4 gets the
final result, as shown below: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYkhPa_BFbyBirwNhvg-e2517jZwLJZp9WVUzhVgHKFzo1ldko8Tp78ywFqHL7E7m1ZoZv9Vdr0FKCV2IOJdW9aH1LQsyvjsQ60Perrw4XRrXJfub5X_cnxdCEUEjH_R0-VuTtGpcPJZA/s1600/esProc_report_transpose_report_11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYkhPa_BFbyBirwNhvg-e2517jZwLJZp9WVUzhVgHKFzo1ldko8Tp78ywFqHL7E7m1ZoZv9Vdr0FKCV2IOJdW9aH1LQsyvjsQ60Perrw4XRrXJfub5X_cnxdCEUEjH_R0-VuTtGpcPJZA/s1600/esProc_report_transpose_report_11.jpg" /></span></a></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Transposition
with dynamic locating</span></span></h3>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">In the database table <i>tb</i>, every 3 records with the same userid are a group. You need to
transform these groups into rows and present result in a report with the table
control. Below is a selection from the table <i>tb</i>:<o:p></o:p></span></span><br />
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 216px;">
<tbody>
<tr style="height: 15.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 15.75pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 12pt;"><span style="font-family: inherit;">userid<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 15.75pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 12pt;"><span style="font-family: inherit;">type<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 15.75pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 12pt;"><span style="font-family: inherit;">descr<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">scooby<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">dog<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">dog<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">scooby<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">weight<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">50<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">scooby<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">hair<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">long<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mickey<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mouse<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mouse<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mickey<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">hair<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"></td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mickey<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">weight<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div align="left" class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">The desired layout is:<o:p></o:p></span></span><br />
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 357px;">
<tbody>
<tr style="height: 15.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 15.75pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">userid <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 15.75pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">type <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 15.75pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.0pt;" width="141"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">hair <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 15.75pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">weight<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 15.75pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 15.75pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mickey<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 15.75pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">mouse<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 15.75pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.0pt;" width="141"></td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 15.75pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">scooby<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">dog<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 106.0pt;" width="141"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">long<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">50<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<span style="font-family: inherit;">esProc script:</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVLn2Z0P5Uz90XgnPqscpXG2iv5YPjy78uXpryU88eU47sSbWbXjKgM-FnE4gUXBazlBi4yOyoGZgu1vYn1rLqteYmJBj1Hg-fvM5MyOYGynnlcgv10ueOBK6ff3s037VyGL3Qll-zvoM/s1600/esProc_report_transpose_report_12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVLn2Z0P5Uz90XgnPqscpXG2iv5YPjy78uXpryU88eU47sSbWbXjKgM-FnE4gUXBazlBi4yOyoGZgu1vYn1rLqteYmJBj1Hg-fvM5MyOYGynnlcgv10ueOBK6ff3s037VyGL3Qll-zvoM/s1600/esProc_report_transpose_report_12.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">The align function aligns data with members of a
set ([‘hair’,’weight’]); @n means placing the unaligned data in a separate row.
As with this example, such a row is composed of records corresponding to mouse
and dog. Here’s the result: </span><br />
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC4EGYquRglSg11FTiOtyJdiRA3A2kbjl3__DGFPSpTPe2W04uYzFPh2obuPO0OeH7X6naCZnKWPB56bEk8qSI2fNajOZ2on4J7EtHGMAffAa5OQPmZ1pXzno-qMkJrs0aPUe7YGfFis4/s1600/esProc_report_transpose_report_13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC4EGYquRglSg11FTiOtyJdiRA3A2kbjl3__DGFPSpTPe2W04uYzFPh2obuPO0OeH7X6naCZnKWPB56bEk8qSI2fNajOZ2on4J7EtHGMAffAa5OQPmZ1pXzno-qMkJrs0aPUe7YGfFis4/s1600/esProc_report_transpose_report_13.jpg" /></span></a></div>
<h3>
<span lang="EN-US"><span style="font-family: inherit; font-size: large;">Column-to-row
transposition with three related tables </span></span></h3>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">There are
three tables – <i>Students</i> table, <i>Exam</i> table and <i>Retest</i> table – which are related between each other through stu_id,
as shown below: <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span lang="EN-US"><span style="font-family: inherit;">Students<o:p></o:p></span></span></i></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 218px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_id<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">class_id<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1-1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Rachel<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1-1<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Emily<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.8pt;" width="73"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1-3<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<i><span lang="EN-US"><span style="font-family: inherit;">Exam<o:p></o:p></span></span></i></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 216px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_id<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">subject<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">score
<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">77<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++ <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">80<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">67<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++ <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">58<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">56<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++ <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">85<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<i><span lang="EN-US"><span style="font-family: inherit;">Retest<o:p></o:p></span></span></i></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 216px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_id<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">subject<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">score<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++ <o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">78<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">82<o:p></o:p></span></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">You need to
query the three tables to get the score of each subject, the total score and
the retest score for every student. Below is the desired layout: <o:p></o:p></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; margin-left: 4.65pt; text-align: center; width: 511px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_id<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">stu_name<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">java_score<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++_score<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">scoresSum<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">javaRetest<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">c++Retest<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">1<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Ashley<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">77<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">80<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">156<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"></td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"></td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">2<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Rachel<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">67<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">58<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">125<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"></td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">78<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">3<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="left" class="MsoNormal">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">Emily<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">56<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">85<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">141<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 56.5pt;" width="75"><div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-size: 11pt;"><span style="font-family: inherit;">82<o:p></o:p></span></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72"></td>
</tr>
</tbody></table>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">esProc
script: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi88k9Qt5Ny_8jzQlGVT1TD7eP-3OHo5bk7lpZFgfl-gQrghDlQ4jxzSkUxrrKq6XfF0rJ9yaSADjLOwskIFvLyYxcoCQQ2PWiNng-ews3OPFiVEMX9YucsK-AUTy-DrHY68SY9fx8vO7Q/s1600/esProc_report_transpose_report_14.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi88k9Qt5Ny_8jzQlGVT1TD7eP-3OHo5bk7lpZFgfl-gQrghDlQ4jxzSkUxrrKq6XfF0rJ9yaSADjLOwskIFvLyYxcoCQQ2PWiNng-ews3OPFiVEMX9YucsK-AUTy-DrHY68SY9fx8vO7Q/s1600/esProc_report_transpose_report_14.jpg" /></span></a></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-51466156583941732832016-03-06T18:29:00.000-06:002016-04-07T02:32:33.621-05:00A Standard Method of Building Reports Presenting Link-Relative Ratios and Year-on-year Growth Rates <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">A link-relative
ratio is a percentage got by comparing the data of current period and that of
the previous period. A year-on-year growth rate is the rate of change expressed
between the current period and the same one from the previous year. Different reporting
tools have different ways to calculate the link relative ratios and the year-on-year
growth rates. Some do the calculations in SQL, some perform the calculations
using elusive controls, and others can only achieve the goals by writing
complicated report scripts. <o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">esProc
supports handling inter-row calculations and the calculations involving
relative positions automatically, enabling a standard method of building reports
that present the link relative ratios and year-on-year growth rates. The method
applies to various reporting tools. So esProc is an ideal tool for report data source
preparation. The reporting tool regards an esProc script as the stored
procedure, passes parameter to it and gets the returned result after execution
through JDBC. Learn more from <b><i><a href="http://blog.raqsoft.com/?p=4665">How
to Use esProc to Assist Reporting Tools<span style="font-style: normal; font-weight: normal;">.</span></a></i></b> The following example will show you how
esProc works. <o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Case description:<o:p></o:p></span></b></div>
<br />
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">Compute
link-relative ratio and year-on-year comparison of growth rate of each month’s
sales amount in a specified period and present the results in a report. Below
is a selection from the <i>Orders</i> table:<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3OjBRpazIMTtNadhAQF5AZkeCODBzO5dyryQ0JhT3lcQSUU2ZvwftwzBgU0bi6ZsHLyNKPntnEc5h1wqJWu66GAVQnfTeguIBS5mjmkiqAqylZOa1_Rhf5ljZP-5NwUqOViatakNurVw/s1600/esProc_youy_lrr_report_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3OjBRpazIMTtNadhAQF5AZkeCODBzO5dyryQ0JhT3lcQSUU2ZvwftwzBgU0bi6ZsHLyNKPntnEc5h1wqJWu66GAVQnfTeguIBS5mjmkiqAqylZOa1_Rhf5ljZP-5NwUqOViatakNurVw/s1600/esProc_youy_lrr_report_1.jpg" /></a></div>
<br />
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">esProc
code:<o:p></o:p></span></b></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A1=esProc.query("select * from
sales3 where OrderDate>=? and OrderDate<=?",begin,end)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A2=A1.groups(year(OrderDate):y,month(OrderDate):m;sum(Amount):mAmount)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A3=A2.derive(mAmount/mAmount[-1]:lrr)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A4=A3.sort(m)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A5=A4.derive(if(m==m[-1],mAmount/mAmount[-1],null):yoy)<o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Code explanation:<o:p></o:p></span></b></div>
<span style="text-indent: 0cm;">A1: Retrieve data from database according to the specified
period.</span><i style="text-indent: 0cm;"> begin</i><span style="text-indent: 0cm;"> and </span><i style="text-indent: 0cm;">end</i><span style="text-indent: 0cm;"> are external parameters. Such as, </span><i style="text-indent: 0cm;">begin="2011-01-01"</i><span style="text-indent: 0cm;">,
</span><i style="text-indent: 0cm;">end="2014-07-08"</i><span style="text-indent: 0cm;">(i.e. the data of the current day which can be
obtained through </span><i style="text-indent: 0cm;">now()</i><span style="text-indent: 0cm;"> function). Below is a selection of the query
result:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj_zqZFgMD_gJ_mSa_iOdiS27UQ4QBM76oN0uuc01Lh8xCUATGuHvXhlJvD3sNcispIcGEMpmYQYxTu28tNhZsNB74jgAf8Mf2_YRDVXQ4M6C7oRzszWbuhmZR4w0Z2qTHQskZ73rHoLg/s1600/esProc_youy_lrr_report_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj_zqZFgMD_gJ_mSa_iOdiS27UQ4QBM76oN0uuc01Lh8xCUATGuHvXhlJvD3sNcispIcGEMpmYQYxTu28tNhZsNB74jgAf8Mf2_YRDVXQ4M6C7oRzszWbuhmZR4w0Z2qTHQskZ73rHoLg/s1600/esProc_youy_lrr_report_2.jpg" /></a></div>
<span style="text-indent: 0cm;">A2: Group orders by the year and the month, and summarize data
to get each month’s sales amount. Some of the computed results are as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwhME9k7Z6xuAJabWXEy3R5PV9IDaE7GPk3ZbO5GRxwvTl2x463sP1oj8-8YamB1hNki5dCUwG0AebbiQmy_zr5_uqibPXvXcznKoXDWcbZlNrc9GBDZ7PiNFNqC6_f9r-XbQZJpzeIx4/s1600/esProc_youy_lrr_report_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwhME9k7Z6xuAJabWXEy3R5PV9IDaE7GPk3ZbO5GRxwvTl2x463sP1oj8-8YamB1hNki5dCUwG0AebbiQmy_zr5_uqibPXvXcznKoXDWcbZlNrc9GBDZ7PiNFNqC6_f9r-XbQZJpzeIx4/s1600/esProc_youy_lrr_report_3.jpg" /></a></div>
<span style="text-indent: 0cm;">A3: Add a new field </span><i style="text-indent: 0cm;">Irr</i><span style="text-indent: 0cm;">, i.e, the link-relative ratio
on a month-on-month basis. The expression is </span><i style="text-indent: 0cm;">mAmount/mAmount[-1]</i><span style="text-indent: 0cm;">, in which </span><i style="text-indent: 0cm;">mAmount</i><span style="text-indent: 0cm;"> represents sales amount of the
current month and </span><i style="text-indent: 0cm;">mAmount[-1]</i><span style="text-indent: 0cm;"> represents that of the previous month.
Note that value of the first month’s (i.e. January 2011) link-relative ratio is
null. Computed results are:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLiaKLfJEzk-NO53FcZqWchxUVuP-cybQPIy0jp7VhWI00m0Ew9IBHv68foR45nemAd-A0D1SgdonO2FaAGQoGW8R5MRv8GP38NmzZs_bp3WcH3q6mJ31EU0nTEnVguAWmQx29R-8XSg/s1600/esProc_youy_lrr_report_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLiaKLfJEzk-NO53FcZqWchxUVuP-cybQPIy0jp7VhWI00m0Ew9IBHv68foR45nemAd-A0D1SgdonO2FaAGQoGW8R5MRv8GP38NmzZs_bp3WcH3q6mJ31EU0nTEnVguAWmQx29R-8XSg/s1600/esProc_youy_lrr_report_4.jpg" /></a></div>
<span style="text-indent: 0cm;">A4: Sort A3 by the month and the year to compute the growth
rate of year-on-year comparison. Complete code should be: </span><i style="text-indent: 0cm;">=A3.sort(m,y)</i><span style="text-indent: 0cm;">.
Since A3 has been sorted by the year, so we just need to sort it by the month, that
is, </span><i style="text-indent: 0cm;">A3.sort(m)</i><span style="text-indent: 0cm;">. This has a higher performance. Some of the computed
results are:</span><span style="text-indent: 0cm;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTOkKncR5gp6h-e1s51gWsqEL5_VWHd6mjj6pvjGGFGiGP7lExUrG_XRjdmKts2X-ik7HVuW3l1CCTIhruCSdfUANhVGd3Nb0Y8-3ec0ylYEL3_A79S-H78W0wkBVN5cCLqoh6EPcDBqo/s1600/esProc_youy_lrr_report_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTOkKncR5gp6h-e1s51gWsqEL5_VWHd6mjj6pvjGGFGiGP7lExUrG_XRjdmKts2X-ik7HVuW3l1CCTIhruCSdfUANhVGd3Nb0Y8-3ec0ylYEL3_A79S-H78W0wkBVN5cCLqoh6EPcDBqo/s1600/esProc_youy_lrr_report_5.jpg" /></a></div>
<span style="text-indent: 0cm;">A5: Add a new field </span><i style="text-indent: 0cm;">yoy</i><span style="text-indent: 0cm;">, i.e., the year-on-year
comparison of monthly sales amount. The expression is </span><i style="text-indent: 0cm;">if(m==m[-1],mAmount/mAmount[-1],null)</i><span style="text-indent: 0cm;">, which means that the comparison </span><span style="text-indent: 0cm;">can only be made
between</span><span style="text-indent: 0cm;"> the same months. Note that the values of </span><span style="text-indent: 0cm;">year-on-year
comparison of </span><span style="text-indent: 0cm;">months in the initial year (i.e. the
year 2011) are always nulls. Some of the computed results are:</span><span style="text-indent: 0cm;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl0bPgOQkcO3mJ0CevhsEPTdEqGYKQZYH4rZWVKyCKlQq0Y5Ov5kw1TBGVdYp_jBerWBuLABhmKhOtbdcpafJioThm4jNXY9XXtoRSWNah8AXUQBb0qZLEfpksjb9wbc50VXLrMK2mFHA/s1600/esProc_youy_lrr_report_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl0bPgOQkcO3mJ0CevhsEPTdEqGYKQZYH4rZWVKyCKlQq0Y5Ov5kw1TBGVdYp_jBerWBuLABhmKhOtbdcpafJioThm4jNXY9XXtoRSWNah8AXUQBb0qZLEfpksjb9wbc50VXLrMK2mFHA/s1600/esProc_youy_lrr_report_6.jpg" /></a></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US">For the convenience of observation, one more line of code, <i>A6=A5.sort(y:-1,m)</i>,
can be added. That is, sort A5 by the year in descending order and by the month
in ascending order. Note that the data ends in July 2014. Results are as
follows: <o:p></o:p></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBBN3dGZRZWRuttmdyOmT0nRbjbY6yZSPYfzuH_Nr6DROKgi42hx1_tpozWchO6bzSiBFGPqQEqs-amXEjZnd4oKiknqUu44IsI_ztAh1WQ9hBY0yi-m0DV0Ax93Cz13GlEVFYOjceOtM/s1600/2016-04-01_090639.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="287" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBBN3dGZRZWRuttmdyOmT0nRbjbY6yZSPYfzuH_Nr6DROKgi42hx1_tpozWchO6bzSiBFGPqQEqs-amXEjZnd4oKiknqUu44IsI_ztAh1WQ9hBY0yi-m0DV0Ax93Cz13GlEVFYOjceOtM/s320/2016-04-01_090639.jpg" width="320" /></a></div>
<span lang="EN-US"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-40105473031583549872016-01-13T19:13:00.002-06:002016-01-13T19:13:49.008-06:00The Three-layered Reporting Architecture <div class="MsoNormal">
<span lang="EN-US">A reporting architecture consists of three
layers from bottom to top – storage layer, computing layer and displaying
layer. The storage layer contains raw data, which may be stored in a relational
database (RDB), a NoSQL database, and a local or HDFS file, or may just be a
JSON stream. The computing layer can access the storage layer to process the structured
and semi-structured raw data to generate the result set that is suitable for
reporting. The displaying layer is responsible for presenting and flavoring data
in the form of a list, a table, a cross table or a chart. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Today, the computing layer is usually embedded
into the storage layer or the displaying layer. In the first case, generally it
is the database that does the computing work; and in the second case, computing
work will be accomplished by reporting scripts (that use the cell function or inter-cell
calculation). <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The advantages of performing computations
in databases are high data consistency, rich basic algorithms and high performance,
but we shouldn’t ignore its disadvantages: <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">1</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US">Despite the
high performance the in-database computation achieves, much of it could be
canceled by the performance loss resulted from retrieving data via JDBC and
conversion from data flow to objects with the reporting tool. That remains a
problem that refuses to be solved. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">2</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US">Simple SQL statements
can be executed fast, but complex ones are not easy to optimize. The
performance of running a stored procedure that uses a <i>for</i> statement for data fetching could reduce exponentially.</span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;">3</span><span style="font-family: 宋体; text-indent: 21pt;">.</span><span lang="EN-US" style="text-indent: 21pt;">SQL isn’t thoroughly
set-oriented, doesn’t promote stepwise computation and lacks support for ordered
sets, rendering natural thinking in SQL and in the stored procedure impossible
and programming in them difficult.</span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;">4</span><span style="font-family: 宋体; text-indent: 21pt;">.</span><span lang="EN-US" style="text-indent: 21pt;">Often a lot
of money is spent in database building and maintenance in order to increase
security and reliability. So it’s reasonable to store only the core business
data, instead of the large number of intermediate tables, in the database.
Unfortunately, most report data sources originate from the intermediate tables.</span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">5</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US">A database
is flat-structured, unable to organize data in multilevel directories and only
capable of managing a small number of tables. In-database computation will
generate many intermediate tables that are related to each other and that may
have confusing names, causing difficulty to data administration. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">6</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US">It’s
difficult to handle multiple/heterogeneous data sources in databases, such as
cross-database computations and computations between database and text file.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Handling computation with reporting tools may
address the shortcomings of in-database computation to some extent, but there
are downsides as well:</span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;">1</span><span style="font-family: 宋体; text-indent: 21pt;">.</span><span lang="EN-US" style="text-indent: 21pt;">In handling
a computation, the reporting tool needs to hide its rows and columns to make
room for storing the intermediate results, increasing memory usage and
decreasing performance.</span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;">2</span><span style="font-family: 宋体; text-indent: 21pt;">.</span><span lang="EN-US" style="text-indent: 21pt;">Apart from storing
values, the grid cells of a report have appearance properties (such as font,
size and background color) that may affect performance. </span></div>
<div class="MsoNormal">
<span lang="EN-US" style="text-indent: 21pt;">3</span><span style="font-family: 宋体; text-indent: 21pt;">.</span><span lang="EN-US" style="text-indent: 21pt;">Reporting
tools can only handle relatively simple computations, such as aggregation and
getting computed columns. They lack the ability to deal with most of the data
handling tasks involving complex computations.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">In sum, there are major drawbacks when embedding
the computing layer into the storage layer or the displaying layer in a
reporting architecture. A better solution is to make it an independent layer.
Specifically, an independent computing layer has the following advantages: <o:p></o:p></span></div>
<h2>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 173%; mso-bidi-font-size: 16.0pt;">Out-of-database algorithms: Reducing dependence on stored
procedures<o:p></o:p></span></h2>
<div class="MsoNormal">
<span lang="EN-US">Stored procedures are managed by the
database, while the report templates are stored in a file system independent of
the database. It’s difficult to map one onto the other. Editing stored
procedures requires programmers to have certain administrative rights for performing
the recompilation, opening the door for potential security issues. Multiple reporting
routines could share one stored procedure, which is very likely to cause tight
coupling between applications, and that, in turn, would mess up the invocation relationships.
It’s complicated to write stored procedures and their computation-oriented
feature brings little advantage in performance. The frequent use of stored
procedures needs outstanding data management skills and huge data
administration cost, but that is beyond most development teams can achieve or
afford. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">An independent computing layer can
significantly reduce the use of the database stored procedures. Algorithms, together
with the report templates, are stored outside databases and belong exclusively
to a single application, which will reduce coupling between reporting routines
and won’t cause coupling between a reporting routine and other types of routines.
<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Here’s an example. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">The database table <i>stateSales</i> contains the sales information of the products in each
state. It has 3 fields – state, product and amount – where there are duplicate
values. Now you need to remove those records with duplicate values and find out
the “popular products whose sales amount in every state ranks top 10” and present
the data of these products in a report. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span lang="EN-US">Traditionally, we would write a stored
procedure to do this. Below is the code:</span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><br /></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">01 create</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">or</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">replace</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">package</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> salesPkg<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">02 as</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">03 type</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> salesCur </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">is</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">ref</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">cursor</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">04 end</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">05 CREATE</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">OR</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">REPLACE</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">PROCEDURE</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> topPro(io_cursor </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">OUT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
salesPkg.salesCur) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">06 is</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">07</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
varSql </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">varchar2</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(</span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">2000</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">);<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">08</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
tb_count </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">integer</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">09 BEGIN</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">10</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">select</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">count</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(*) </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">into</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> tb_count </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">from</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> dba_tables </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">where</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> table_name=</span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">'TOPPROTMP'</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">11</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">if</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> tb_count=</span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">0</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">then</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">12</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
strCreate:=</span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">'CREATE GLOBAL TEMPORARY TABLE TOPPROTMP ( <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateTmp NUMBER
not null, <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> productTmp
varchar2(10) not null,<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> amountTmp
NUMBER not null<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> ) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> ON COMMIT PRESERVE
ROWS'; <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">13</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">execute</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">immediate</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> strCreate;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">14</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">end</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">if</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">15</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">execute</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">immediate</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">'truncate table
TOPPROTMP'</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">16</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">insert</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">into</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
TOPPROTMP(stateTmp,productTmp,amountTmp) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">select</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> state,product,amount </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">from</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateSales a <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">where</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">not</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> (a.state,a.product) </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">in</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> (<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">select</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> state,product </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">from</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateSales </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">group</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">by</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> state,product </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">having</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">count</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(*) > </span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">1</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> ) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">and</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">rowid</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">not</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">in</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> (<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">select</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">min</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">rowid</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">) </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">from</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateSales </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">group</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">by</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> state,product </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">having</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">count</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(*)></span><span lang="EN-US" style="background: white; color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">1</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"><o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> )<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> )<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">order</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">by</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> state,product;<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">17</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">OPEN</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> io_cursor </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">for</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">18</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">SELECT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> productTmp </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">FROM</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> (<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="text-indent: 21pt;">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">SELECT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
stateTmp,productTmp,amountTmp,rankorder<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="text-indent: 21pt;">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">FROM</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> (</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">SELECT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">
stateTmp,productTmp,amountTmp,RANK() OVER(</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">PARTITION</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">BY</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateTmp </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">ORDER</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">BY</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> amountTmp </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">DESC</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">) rankorder <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="background: white; mso-highlight: white;"> <span style="color: teal;">FROM</span>
TOPPROTMP<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> ) <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="background: white; mso-highlight: white;"> <span style="color: teal;">WHERE</span>
rankorder<=<span style="color: blue;">10</span> <span style="color: teal;">order</span>
<span style="color: teal;">by</span> stateTmp<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> )<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="background: white; mso-highlight: white;"> <span style="color: teal;">GROUP</span> <span style="color: teal;">BY</span> productTmp <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">HAVING</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">COUNT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(*)=(</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">SELECT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">COUNT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">(</span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">DISTINCT</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> stateTmp ) </span><span lang="EN-US" style="background: white; color: teal; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;">FROM</span><span lang="EN-US" style="background: white; color: navy; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: white;"> TOPPROTMP);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="background: white; mso-highlight: white;">END<span style="color: navy;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">With a separate computing layer, the
algorithm can be implemented with coupling not being an issue any more. We can
choose to use high-level languages like JAVA, or data-computing class libraries
such as Pandas and esProc, to perform the computation. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Using JAVA as the computing layer raises
two problems. First, the computing layer should be taken care of separately or
with report templates. But since JAVA is a compiled language, the computing
code that is ready to use needs to be compiled and packaged with the main reporting
tool program, thus increasing, instead of decreasing the coupling and disabling
realization of independent modules. Second, JAVA is not as professional as the data-computing
class libraries, in that it needs to do bottom-up programming starting with the
basic algorithms. That demands a lot of work. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Both Pandas and esProc are professional data-computing
libraries. But Pandas lacks an easy-to-use JDBC interface for receiving
invocation from the reporting tool. That’s why we take esProc here for illustration. <o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_13ycOJ2NsY3HA4bWVRU_KOWKhcz8Aofiyh4_PaRJGWr_kG37Sb8gRR-l7sYCcW8kn9QU2myXCnw3NPLJieihiBmI7aiOk5xTXXfyP4irUoqDLx_5x2yddHCeuhvbSQuvkzu46nmE6aw/s1600/2016-01-14_090649.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_13ycOJ2NsY3HA4bWVRU_KOWKhcz8Aofiyh4_PaRJGWr_kG37Sb8gRR-l7sYCcW8kn9QU2myXCnw3NPLJieihiBmI7aiOk5xTXXfyP4irUoqDLx_5x2yddHCeuhvbSQuvkzu46nmE6aw/s1600/2016-01-14_090649.jpg" /></a></div>
<br />
<div class="MsoNormal">
<span lang="EN-US">A2 removes the records with duplicate
values. A3 groups records by state. B3 gets the sequence numbers of the top 10
products in each group. A4 gets the products from each group according to their
sequence numbers. A5 calculates the intersection between groups. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Save the above script as the <i>topPro.dfx</i> file and call it from the
reporting tool via JDBC. The calling method is the same as that of calling a
stored procedure. With BIRT, for instance, we can call the script using this
statement: </span><span lang="EN-US" style="color: #0070c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-weight: bold; mso-font-kerning: 0pt;">call</span><span lang="EN-US" style="color: #0070c0; font-family: Consolas; font-size: 10.0pt; mso-font-kerning: 0pt;"> topPro() </span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The above esProc script is simple, clear, and
easy to develop and maintain, as well as allows interpreted execution. The
script requires only the select right to access the database, without the need
of higher levels of rights to perform modification and editing. It can be
stored with the corresponding report template to gain easy maintenance. <o:p></o:p></span></div>
<h2>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 173%; mso-bidi-font-size: 16.0pt;">Out-of-database data: Reducing intermediate tables<o:p></o:p></span></h2>
<div class="MsoNormal">
<span lang="EN-US">An intermediate table is an intermediate
result set got through data arrangement and aggregation that needs to be
performed in advance because of the large amount of data or the computational
complexity. It serves as the source of data of the report and makes report
development easier and more efficient. However, similar to the stored procedures,
intermediate tables are difficult to manage, potentially vulnerable to security
threats, error-prone during invocations and costly to develop. Particularly,
those tables will take up large database space, holding hardware and software costs
on a rather high level. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Generally, intermediate tables are
calculated from static historical data, so they don’t demand the ability of
maintaining transaction consistency the databases have, and, for being the
redundant data, a high degree of security and steadiness. They are stored in
databases just for obtaining computational power. We can retrieve these
intermediate results from databases as external data files which will then be
handled by the computing layer. In this way, intermediate tables will become
much fewer. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The intermediate data that has been moved out
of a database can be managed by a file system in a tree structure and stored
with the matching report templates and data preprocessing algorithms. An
independent computing layer can sustain the intermediate data’s powerful
computational ability for use in report creation. With this arrangement, data
is more easily and conveniently managed and occupies less database space while maintaining
a lower overhead. Moreover, file systems have higher IO performance than
databases, and thus more suitable for being used in report development tasks. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Here’s an example. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">The <i>Orders</i>
table contains core business data from which a number of intermediate tables
are generated. One of them is the <i>sumOrders</i>
table in which sales amounts are summarized according to clients, sellers,
years and month. Now we need to query data in certain years in <i>sumOrders</i>, calculate the link relative
ratio of each month and present the result in a report. Below is the table: <o:p></o:p></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 360px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="border-bottom: none; border-left: solid windowtext 1.0pt; border-right: none; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">Client<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">SellerId<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">year<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-top: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">month<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-bottom: none; border-left: none; border-right: solid windowtext 1.0pt; border-top: solid windowtext 1.0pt; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">amount<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">ARO<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">498<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2014<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">10<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">1814<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">ARO<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">499<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2013<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">10<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">4709<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">BDR<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">26<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2014<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">10<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">990<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">BDR<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">41<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2014<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">1<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">554<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 5;">
<td nowrap="" style="border-left: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">BDR<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">51<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2014<o:p></o:p></span></div>
</td>
<td nowrap="" style="border: none; height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">11<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-right: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">7<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: solid windowtext 1.0pt; border-right: none; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">BDR<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">56<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2013<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">1<o:p></o:p></span></div>
</td>
<td nowrap="" style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 13.5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 54.0pt;" width="72">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">4437<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
Import the <i>sumOrders</i> table as an external file (or we can import the desired
data from the core business data table), handle the file in the computing
layer, and then return result to the reporting tool. Take esProc as an example
and the code will be as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5Yhq-1TbYWsK_k4eXiXAAsIAfhjQtQkUN85dfwTwS05Ls7hl1-hNCNhBdkpcaCdyMMjU1q3lJ6djx8gzYxOJrv6mfxDmspZ0DKDx-8N0Guk1rEOGiDWID6Jaj-uM1cLuhrDBVIDhQV0c/s1600/2016-01-14_090705.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5Yhq-1TbYWsK_k4eXiXAAsIAfhjQtQkUN85dfwTwS05Ls7hl1-hNCNhBdkpcaCdyMMjU1q3lJ6djx8gzYxOJrv6mfxDmspZ0DKDx-8N0Guk1rEOGiDWID6Jaj-uM1cLuhrDBVIDhQV0c/s1600/2016-01-14_090705.jpg" /></a></div>
<br />
Explanation:
Import the text file into the memory with tab being the separator and the first
row being the filed names. Then query desired data according to the parameter
and perform aggregation by month. Finally, calculate the link relative ratio,
in which total[-1] represents the sales amount of the previous month. Result is
as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2bQ4zyjltyQZoAymTS47I8MWIxYPqF5o_aeqTB74c-RjBaYWxEm1dNjIQFSJ4UU78XNTSPZGx58CSIk7DUg8B_ANmqOZ38QztZSytGYVRf7OmQYD66SziqSo1Xc0SPi4153BGGCe99dI/s1600/2016-01-14_090714.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2bQ4zyjltyQZoAymTS47I8MWIxYPqF5o_aeqTB74c-RjBaYWxEm1dNjIQFSJ4UU78XNTSPZGx58CSIk7DUg8B_ANmqOZ38QztZSytGYVRf7OmQYD66SziqSo1Xc0SPi4153BGGCe99dI/s1600/2016-01-14_090714.jpg" /></a></div>
<h2>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 173%; mso-bidi-font-size: 16.0pt;">A controlling computing layer: Enabling T+0 reports<o:p></o:p></span></h2>
<div class="MsoNormal">
<span lang="EN-US">A T+0 report is one that presents both the
current and historical transaction data. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Historical data has two characteristics: First,
it is huge, which causes high database space usage and hardware and software
costs. Second, it’s continually expanding, which could affect the current
transaction. The traditional idea in response to the problems is keeping only the
useful part of the historical data in the current transaction database and
moving the rest of it out to build a separate database. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Consequently, programmers and developers
are only able to create reports based only on either the present data or the past
data, but unable to create a report based on both present and past data, making
a T+0 report impossible. To build and view such a report, cross-database
querying is needed. Theoretically, many databases support cross-database
queries by mapping data from another database into the database currently
handled and retrieving the data into the current database for handling if an
analysis is needed. But this way, the actual performance and steadiness is
rather unsatisfactory and the overhead is fairly high. On the other hand, a historical
database has large storage capacity and doesn’t require transaction consistency,
so it is most probably that it is a different type of database. Under such
circumstances, the computing mechanisms provided by database vendors for
cross-database data handling are hard to put into practice. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Yet, with an independent computing layer,
high-performance, low-cost, stable cross-database data handling can be
achieved. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Independent of any specific database, a
computing layer can realize T+0 reports solidly. It permits each database to
handle its own data while it collects result sets to summarize and returns the
final result to the reporting tool for presentation. Apparently, this mechanism
supports scaling out better and allows for different types of historical
databases. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Here’s an example. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">A telecom company stores user service
information in the database table <i>userService</i>.
You need to build a T+0 report for displaying the call duration, number of
calls, duration of local calls and number of local calls. The actual operation
shows that the report building performance is not good because data is huge but
the queries are very inefficient. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">We can greatly increase the reporting
performance by using an independent computing layer. This is how it goes: store
the <i>userService</i> table in multiple
databases and perform parallel processing in the computing layer. <o:p></o:p></span></div>
In esProc, the code will be like this:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-LyyAzZagvy68Tlow4hRYQ-LXh1iLrO5oX-k5URKSPSc4PX1yYrMDvTrtdwpxXhx0xNLPeSuaNSOt0VWChgwn6j3lh_3p1oT3lMJn8WinZ5bpZfUwKUffib05QqlYt1JT49wxQcMQgp4/s1600/2016-01-14_090747.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-LyyAzZagvy68Tlow4hRYQ-LXh1iLrO5oX-k5URKSPSc4PX1yYrMDvTrtdwpxXhx0xNLPeSuaNSOt0VWChgwn6j3lh_3p1oT3lMJn8WinZ5bpZfUwKUffib05QqlYt1JT49wxQcMQgp4/s1600/2016-01-14_090747.jpg" /></a></div>
<br />
<div class="MsoNormal">
<span lang="EN-US">The <i>fork</i>
statement launches the parallel processing with four subthreads, each of which
retrieves data from a database and returns its own group and aggregate result
to the main thread that merges the subthreads’ results and performs a second
group and aggregate to obtain the desired result set for reporting. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Popular reporting tools generally fail to provide
the capability of performing parallel retrieval and aggregation, and,
therefore, turn to high-level languages, like Java, to do that. But it’s
difficult to write parallel code in Java and the language lacks the ability of
handling structured data, so the effect is no match for the one achieved
through an independent computing layer. <o:p></o:p></span></div>
<h2>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 173%; mso-bidi-font-size: 16.0pt;">Handling various data sources directly <o:p></o:p></span></h2>
<div class="MsoNormal">
<span lang="EN-US">An independent computing layer supports
many different types of data sources, such as NoSQL databases, file data and HTTP
data, and can directly handle them without importing them into the RDBs, saving
the effort of building extra databases, as well as lowering cost and the risk
of data inconsistency. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">In some aspects, NoSQL databases offer
superior performance than RDBs, but they don’t have sufficient computational
power or each do computations in a distinctive way. If we can enable cooperation
between NoSQL databases and the independent computing layer, we can sustain the
former’s strengths. For example, the throughput of MongoDB is significantly
higher than the throughput ordinary RDBs can achieve when transferring
append-only log data, but since the NoSQL database is weak in handling
structured data, it needs a database middleware or a Java middleware. An
independent computing layer can sustain the high-throughput of MongoDB while injecting
into it sufficient ability of processing structured data. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Here’s an example. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">A MongoDB Collection last3 has two fields:
variable and timestamp. We want to group data by variable and find from each
group of documents the three ones with the biggest timestamp values and the ten
ones with the smallest timestamp values. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">Below is a selection of the raw data:</span></div>
<div class="MsoNormal">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 426.1pt;" valign="top" width="568">
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997857"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "A",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1995-01-01T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" : ObjectId("54f69645e4b077ed8d997856"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "A",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1995-01-02T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997855"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "A",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1995-01-03T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997854"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "B",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1995-01-02T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997853"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "B",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1995-01-01T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997852"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "B",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1994-01-03T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997851"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "C",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1994-01-03T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997850"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "C",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1994-01-02T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997858"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "C",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1994-01-01T00:00:00Z")}<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">{"_id" :
ObjectId("54f69645e4b077ed8d997859"),<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"variable" : "C",<o:p></o:p></span></div>
<div align="left" class="MsoNormal" style="background: white; vertical-align: baseline;">
<span lang="EN-US" style="color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt;">"timestamp" : ISODate("1993-01-01T00:00:00Z")}<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">In
a conventional way, we need to use a Java middleware and return the result to
the reporting tool through a user-defined data source interface. The code is
cumbersome and the process is complicated. An independent computing layer can
directly use the MongoDB data source and return result to the reporting tool. Take
esProc for example, the code will be like this:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiycQldLqHHUzim9Fzo6K_92ViYEnJ-T9_7gg3yAyzWWPYWJcHVWONZhpXL0PUcCSyczFzjb0Hn439O0Ymy205yk9QmLBMBA9vKLeySYMsY8EW07p8RP9fxae8aylP_70wEz25_Sqji-VA/s1600/2016-01-14_090802.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiycQldLqHHUzim9Fzo6K_92ViYEnJ-T9_7gg3yAyzWWPYWJcHVWONZhpXL0PUcCSyczFzjb0Hn439O0Ymy205yk9QmLBMBA9vKLeySYMsY8EW07p8RP9fxae8aylP_70wEz25_Sqji-VA/s1600/2016-01-14_090802.jpg" /></a></div>
<div class="MsoNormal">
<span lang="EN-US"></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">Explanation: Connect to MongoDB, group data
by variable and retrieve the collection last3 as a cursor (big data handling supported).
Then run a loop to import a group of documents with the same variable value
into the memory each time, and during each loop get the three documents with
biggest timestamp values and append them to B2. After that A5 gets from B2 the
ten documents with the smallest timestamp values. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-52956626389763643382016-01-07T00:50:00.002-06:002016-01-07T00:58:11.941-06:00A Middleware for Data Reporting <div class="MsoNormal">
<span lang="EN-US">Traditionally,
there are three ways to prepare data source for reporting: </span><br />
<span lang="EN-US">1.Retrieve data by
directly connecting the reporting tool to the database and submit SQL
statements to the database in which data source is prepared; </span><br />
<span lang="EN-US">2.Partial data preparation
is made by the reporting tool using its own computing capabilities (functions for
handling grid cells or calculations between them); </span><br />
<span lang="EN-US">3.The reporting tool will
use API to call a Java program to accomplish the data preparation. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">In
this article, let’s compare the three ways and try to find out an optimal
solution. <o:p></o:p></span><br />
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<b><span lang="EN-US">Data
preparation with database <o:p></o:p></span></b><br />
<b><span lang="EN-US"><br /></span></b></div>
<div class="MsoNormal">
<span lang="EN-US">Advantages:
High data integrity, rich basic algorithms and high-performance in-database
computation. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">Disadvantages:
<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">1.</span><span lang="EN-US">Despite the
high performance the in-database computation achieves, much of it could be
canceled by the performance loss – a persistent problem – resulted from retrieving
data by the reporting tool via JDBC and conversion from data flow to objects. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">2.</span><span lang="EN-US">Simple SQL statements
are executed rapidly, but complex ones are not easy to optimize. The stored
procedure that uses a <i>for</i> statement
for data fetching could be even slower than Java.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">3.</span><span lang="EN-US" style="text-indent: 21pt;">SQL isn’t thoroughly
set-oriented; doesn’t promote stepwise computation and support ordered sets and
object reference. These shortcomings make natural thinking in SQL and the
stored procedure impossible and programming in them difficult.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">4.</span><span lang="EN-US" style="text-indent: 21pt;">The building
and maintenance of a database is expensive, so it’s reasonable to store only
the core business data, instead of the intermediate tables, in it. Unfortunately,
most report data sources originate from the intermediate tables.</span><br />
<span lang="EN-US"><br /></span>
<span lang="EN-US">5.</span><span lang="EN-US">A database
is flat-structured, only capable of managing a small number of tables and unable
to organize data in multilevel directories. In-database computation will
generate a large number of intermediate tables that are related to each other
and that may have confusing names, causing difficulty to data administration.</span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">6.</span><span lang="EN-US">It’s
difficult to handle multiple/heterogeneous data sources in databases, such as
cross-database computations and computations between database and text file. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">7.</span><span lang="EN-US">The tightly
coupled storage and computing structures reduce portability and scalability. <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-US"><br /></span></b>
<b><span lang="EN-US">Data
preparation with reporting tools <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US"> Advantages:
It addresses the shortcomings of in-database computation to some extent.</span><br />
<span style="text-indent: 21pt;"><br /></span>
<span style="text-indent: 21pt;">Disadvantages:</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">1.</span><span lang="EN-US" style="text-indent: 21pt;">In handling
a computation, the reporting tool has to hide its rows and columns to make room
for storing the intermediate results, increasing memory usage and decreasing performance.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">2.</span><span lang="EN-US" style="text-indent: 21pt;">Apart from
storing values, the grid cells of a report have appearance properties (such as
font, size and background color) that may affect performance. </span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">3.</span><span lang="EN-US" style="text-indent: 21pt;">Reporting
tools can only handle relatively simple computations, such as aggregation and
getting computed columns. They lack the ability to deal with most of the common
data handling tasks like related computing, set operations and multistep
computations.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">4.</span><span lang="EN-US" style="text-indent: 21pt;">The tightly
coupled storage and data presentation structures reduce portability and
scalability.</span></div>
<div class="MsoNormal">
<b><span lang="EN-US"><br /></span></b>
<b><span lang="EN-US">Data
preparation with Java program <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span>
<span lang="EN-US">Advantages:</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">1.</span><span lang="EN-US" style="text-indent: 21pt;">A Java
program can access file data through parallel processing to enhance the
performance and capacity of a reporting tool.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">2.</span><span lang="EN-US" style="text-indent: 21pt;">A Java
program can handle multiple/heterogeneous data sources.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">3.</span><span lang="EN-US" style="text-indent: 21pt;">A Java
program enables programmers and developers to retrieve core business data from database
and store and get the large number of intermediate tables from files,
effectively alleviating the database pressure.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">4.</span><span lang="EN-US" style="text-indent: 21pt;">A Java
program permits accessing multiple databases simultaneously to realize real-time
big data query (T+0) and display newly-generated data in the report.</span><br />
<span style="text-indent: 21pt;"><br /></span>
<span style="text-indent: 21pt;">Theoretically, a
Java program is the optimal solution. Because it works as a middleware between
the database and the reporting tool to separate storage, computing and
presentation from each other and reduce coupling for the whole system. However,
there’s a major drawback to the Java program. It doesn’t possess the capability
for structured-data handling and thus can only manage the simplest computing scenarios.</span><br />
<span style="text-indent: 21pt;"><br /></span>
<span style="text-indent: 21pt;">esProc can serve
as Java’s extended class library to solve the basic class library issue and
still cover the four Java merits. It has these features:</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">1.</span><span lang="EN-US" style="text-indent: 21pt;">esProc
provides a wide selection of class libraries for handling semi-structured and
structured data. They enable stepwise computing model, complete set
orientation, ordered sets and object reference mechanism, making the
programming more natural and simpler, and producing concise code.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">2.</span><span lang="EN-US" style="text-indent: 21pt;">An esProc
script can be saved as a dfx file and place in a directory together with the corresponding
report file, simplifying the code management process.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">3.</span><span lang="EN-US" style="text-indent: 21pt;">esProc is an
interpreted language and doesn’t need to be compiled and packaged. </span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">4.</span><span lang="EN-US" style="text-indent: 21pt;">esProc
encapsulates the Java multithreaded programming to simplify and facilitate the development.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">5</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US" style="text-indent: 21pt;">esProc
accepts invocation from reporting tools through integration-friendly and
cost-effective JDBC interface.</span><br />
<span lang="EN-US" style="text-indent: 21pt;"><br /></span>
<span lang="EN-US" style="text-indent: 21pt;">For more
information, please see </span><b style="text-indent: 21pt;"><span lang="EN-US"><a href="http://blog.raqsoft.com/?p=4665">How to Use esProc to Assist Reporting
Tools</a></span></b><span lang="EN-US" style="text-indent: 21pt;">.</span></div>
<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-86635957459290455732015-09-17T09:00:00.000-05:002015-09-17T09:00:00.544-05:00An esProc Code Example of Computing Link-Relative Ratio and Year-on-year Comparison <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">A link-relative
ratio is a percentage got by comparing the data of current period and that of
the previous period. Usually the interval between the two periods is a month (sometimes
an hour, a day, a week and a quarter). The link-relative ratio of April is computed
by dividing, for example, its sales amount by that of March. A year-on-year
comparison is a comparison between the current period and the same one from the
previous year. For example, the comparison between sales amount of April 2014 and
that of April 2013. In practical business, data of multiple periods is usually compared
in order to find the variation trend. <o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">The
inter-row and inter-group computations related to link-relative ratio and
year-on-year comparison are common and can be easily handled with esProc. The
following example will show you how esProc works. <o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Case description:<o:p></o:p></span></b></div>
<br />
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">Compute
link-relative ratio and year-on-year comparison of growth rate of each month’s
sales amount in a specified period. Below is a selection from the <i>Orders</i> table:<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8_5wtgjOKgSheUum8yxyxKeuoBm5jO-2eCU7zSCx_-srMAOUORuvyrX0CS1FL2TMR_CU4dO-2ybKMSECxj-dpcVN4G9xraDAgMyAdbuzyBqTjjd6L2sV9oxzPP90vBvse_-_hqe3BcgI/s1600/esProc_inmemory_relative_ratio_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8_5wtgjOKgSheUum8yxyxKeuoBm5jO-2eCU7zSCx_-srMAOUORuvyrX0CS1FL2TMR_CU4dO-2ybKMSECxj-dpcVN4G9xraDAgMyAdbuzyBqTjjd6L2sV9oxzPP90vBvse_-_hqe3BcgI/s1600/esProc_inmemory_relative_ratio_1.jpg" /></a></div>
<br />
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">esProc
code:<o:p></o:p></span></b></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A1=esProc.query("select * from
sales3 where OrderDate>=? and OrderDate<=?",begin,end)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A2=A1.groups(year(OrderDate):y,month(OrderDate):m;sum(Amount):mAmount)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A3=A2.derive(mAmount/mAmount[-1]:lrr)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A4=A3.sort(m)<o:p></o:p></span></div>
<div align="left" class="1" style="text-indent: 0cm;">
<span lang="EN-US" style="color: #1f497d;">A5=A4.derive(if(m==m[-1],mAmount/mAmount[-1],null):yoy)<o:p></o:p></span></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<br /></div>
<div class="1" style="mso-char-indent-count: 0; mso-outline-level: 1; text-indent: 0cm;">
<b><span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Code explanation:<o:p></o:p></span></b></div>
<span style="text-indent: 0cm;">A1: Retrieve data from database according to the specified
period.</span><i style="text-indent: 0cm;"> begin</i><span style="text-indent: 0cm;"> and </span><i style="text-indent: 0cm;">end</i><span style="text-indent: 0cm;"> are external parameters. Such as, </span><i style="text-indent: 0cm;">begin="2011-01-01"</i><span style="text-indent: 0cm;">,
</span><i style="text-indent: 0cm;">end="2014-07-08"</i><span style="text-indent: 0cm;">(i.e. the data of the current day which can be
obtained through </span><i style="text-indent: 0cm;">now()</i><span style="text-indent: 0cm;"> function). Below is a selection of the query
result:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi50gh2P_8hTWUDJswZZ-e2f2IPTNpfjbNMn313vsi7sZgvQNZjiEjaJ1T5omA2DmEOmf8tzQ_9lvpfWAlSgyv0DenFFqiUMW-yrwi3wv6lgiRrCGJNvii2pB_Ut9VKDHLSKOLZjVnKIoM/s1600/esProc_inmemory_relative_ratio_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi50gh2P_8hTWUDJswZZ-e2f2IPTNpfjbNMn313vsi7sZgvQNZjiEjaJ1T5omA2DmEOmf8tzQ_9lvpfWAlSgyv0DenFFqiUMW-yrwi3wv6lgiRrCGJNvii2pB_Ut9VKDHLSKOLZjVnKIoM/s1600/esProc_inmemory_relative_ratio_2.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">A2: Group orders by the year and the month, and summarize data
to get each month’s sales amount. Some of the computed results are as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzBYbr775Tpn6kW385v2tEnMX2bHNFs4dpDJGUKGfCz7yznEYeJUs_sT27Gl5eWh8n9na1Ysi5huN-y9G2mnlFv8gWrjqQBrz6cIrIm4pXC_vyJXuwyFPa_7_lbC02pb7pOZwvNBLBL6c/s1600/esProc_inmemory_relative_ratio_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzBYbr775Tpn6kW385v2tEnMX2bHNFs4dpDJGUKGfCz7yznEYeJUs_sT27Gl5eWh8n9na1Ysi5huN-y9G2mnlFv8gWrjqQBrz6cIrIm4pXC_vyJXuwyFPa_7_lbC02pb7pOZwvNBLBL6c/s1600/esProc_inmemory_relative_ratio_3.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">A3: Add a new field </span><i style="text-indent: 0cm;">Irr</i><span style="text-indent: 0cm;">, i.e, the link-relative
ratio on a month-on-month basis. The expression is </span><i style="text-indent: 0cm;">mAmount/mAmount[-1]</i><span style="text-indent: 0cm;">, in which </span><i style="text-indent: 0cm;">mAmount</i><span style="text-indent: 0cm;"> represents sales amount of the
current month and </span><i style="text-indent: 0cm;">mAmount[-1]</i><span style="text-indent: 0cm;"> represents that of the previous month.
Note that value of the first month’s (i.e. January 2011) link-relative ratio is
null. Computed results are:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdVR9Bx5U_KyaG8BCyOx4O_Fb30qdcyc2L0oEpsfAmUgtvd23OhVB89yJBL5oEKSkNSKEIuYU_m8DjgG1dEgTp94lMhTqruZzBDYXGgS0B9KotxmSU60g7f7Bqo09OVtd8NiwOyQhEqhY/s1600/esProc_inmemory_relative_ratio_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="144" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdVR9Bx5U_KyaG8BCyOx4O_Fb30qdcyc2L0oEpsfAmUgtvd23OhVB89yJBL5oEKSkNSKEIuYU_m8DjgG1dEgTp94lMhTqruZzBDYXGgS0B9KotxmSU60g7f7Bqo09OVtd8NiwOyQhEqhY/s320/esProc_inmemory_relative_ratio_4.jpg" width="320" /></a></div>
<br />
<span style="text-indent: 0cm;">A4: Sort A3 by the month and the year to compute the growth
rate of year-on-year comparison. Complete code should be: </span><i style="text-indent: 0cm;">=A3.sort(m,y)</i><span style="text-indent: 0cm;">.
Since A3 has been sorted by the year, so we just need to sort it by the month, that
is, </span><i style="text-indent: 0cm;">A3.sort(m)</i><span style="text-indent: 0cm;">. This has a higher performance. Some of the computed
results are:</span><span style="text-indent: 0cm;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqlyxBX12gzNxqA-oXaHe8uvRylunNPuql978QMHbbufVWybb2cDyAYCoVsbm9LEOY4u1dDVDzCjsXqaqaZXny2AsWkJASPoCn8LmcLCemXKWLgbnQoe_EquSW7fJ_GTnXBZLZsp6RzUo/s1600/esProc_inmemory_relative_ratio_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqlyxBX12gzNxqA-oXaHe8uvRylunNPuql978QMHbbufVWybb2cDyAYCoVsbm9LEOY4u1dDVDzCjsXqaqaZXny2AsWkJASPoCn8LmcLCemXKWLgbnQoe_EquSW7fJ_GTnXBZLZsp6RzUo/s320/esProc_inmemory_relative_ratio_5.jpg" width="320" /></a></div>
<br />
<span style="text-indent: 0cm;">A5: Add a new field </span><i style="text-indent: 0cm;">yoy</i><span style="text-indent: 0cm;">, i.e., the year-on-year
comparison of monthly sales amount. The expression is </span><i style="text-indent: 0cm;">if(m==m[-1],mAmount/mAmount[-1],null)</i><span style="text-indent: 0cm;">, which means that the comparison </span><span style="text-indent: 0cm;">can only be made
between</span><span style="text-indent: 0cm;"> the same months. Note that the values of </span><span style="text-indent: 0cm;">year-on-year
comparison of </span><span style="text-indent: 0cm;">months in the initial year (i.e. the
year 2011) are always nulls. Some of the computed results are:</span><span style="text-indent: 0cm;"> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVsCjSlavcAl13nH052VfR9zuPI2Wi9PSN5-nmSuw_D9-dew53EgdQyjJ7mXK_EboNvTn9YQjYEpHWD2MFYuX3-c3j3wjzhpW4UlBu7CbMKYYckOWWQaejsqxEkI-_uFn7W-3a1CqhMEU/s1600/esProc_inmemory_relative_ratio_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="220" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVsCjSlavcAl13nH052VfR9zuPI2Wi9PSN5-nmSuw_D9-dew53EgdQyjJ7mXK_EboNvTn9YQjYEpHWD2MFYuX3-c3j3wjzhpW4UlBu7CbMKYYckOWWQaejsqxEkI-_uFn7W-3a1CqhMEU/s320/esProc_inmemory_relative_ratio_6.jpg" width="320" /></a></div>
<br />
<span style="text-indent: 0cm;">For the convenience of observation, one more line of code, </span><i style="text-indent: 0cm;">A6=A5.sort(y:-1,m)</i><span style="text-indent: 0cm;">,
can be added. That is, sort A5 by the year in descending order and by the month
in ascending order. Note that the data ends in July 2014. Results are as
follows: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYatKG1uV4RjdxBeLRP2w1iEm2k14ffSYxOWvZFR7Fibq69f0zmmL7-YBUd0sWqtlsgxdkl509L_1fTFBcQq8iENnutNPTOaBjENeKibDbW07hKQLI6_xrKdsl4HuhV-p6bb2b8AO72AE/s1600/esProc_inmemory_relative_ratio_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYatKG1uV4RjdxBeLRP2w1iEm2k14ffSYxOWvZFR7Fibq69f0zmmL7-YBUd0sWqtlsgxdkl509L_1fTFBcQq8iENnutNPTOaBjENeKibDbW07hKQLI6_xrKdsl4HuhV-p6bb2b8AO72AE/s320/esProc_inmemory_relative_ratio_7.jpg" width="320" /></a></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><br /></span></div>
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-88463236418172843682015-09-15T07:11:00.000-05:002015-09-15T07:11:04.788-05:00Grouping In-memory Data Using esProc: Code Examples<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;">Using esProc, it is quite convenient to group data in memory. There are several main types of grouping based on how data is grouped. Here we’ll illustrate equal grouping, alignment grouping and enumeration grouping respectively with an example.<o:p></o:p></span></span></div><h2><span lang="EN-US" style="line-height: 173%;"><span style="font-family: inherit; font-size: small;">Equal grouping<o:p></o:p></span></span></h2><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;">That data is grouped by one or more certain fields (or one or more computed fields derived from fields) of the current data set is equal grouping. By this method each group is a subset of the original data set.<o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><b><span lang="EN-US">Case description</span></b><span lang="EN-US">: Group sales orders by the year. <o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><br />
<div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><b><span lang="EN-US">Data description</span></b><span lang="EN-US">: The original data is as follow: <o:p></o:p></span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV2JxrG7SAgFIkR-waV1tVOcpNLyQooXiKT7cxAf8FH1FZ1gF5Wx-XUCPjfDPEnw6cs3hDzGNIBSx0I0MSH3DF4DHqFVFsv9e1E6juTWVFBvbPC16eJKdKZtr0fglGtp1wKkGbXhT1thk/s1600/esProc_inmemory_group_code_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV2JxrG7SAgFIkR-waV1tVOcpNLyQooXiKT7cxAf8FH1FZ1gF5Wx-XUCPjfDPEnw6cs3hDzGNIBSx0I0MSH3DF4DHqFVFsv9e1E6juTWVFBvbPC16eJKdKZtr0fglGtp1wKkGbXhT1thk/s1600/esProc_inmemory_group_code_1.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;">The above data set (table sequence) can be imported from a database or a file. For example: <o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A1=file("E:/sales.txt").import@t()<o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><b><span lang="EN-US"><span style="font-family: inherit;">esProc code:<o:p></o:p></span></span></b></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><b><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></b></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK15"></a><a href="https://www.blogger.com/null" name="OLE_LINK14"><span lang="EN-US" style="color: #1f497d;">A2=A1.group(year(OrderDate))</span></a><span lang="EN-US" style="color: #1f497d;"><o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK14"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;"><br />
</span></span></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK19"></a></span></div><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK18" style="text-indent: 0cm;"><b><span lang="EN-US">Computed result:</span></b></a> </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo2sgew08Kyd_qhgEexIF5IZykggKU9GbLhSgvNIw0b1wQTO8s9eRrqxW8qf2OB9nmh7WQuXmDSj2VNOv0Jf6_xzBBrJw7s3Tg8lOeStTx6CPuRjhCYMhuM8z7FvCVKFPG4QeTGAWOoTs/s1600/esProc_inmemory_group_code_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo2sgew08Kyd_qhgEexIF5IZykggKU9GbLhSgvNIw0b1wQTO8s9eRrqxW8qf2OB9nmh7WQuXmDSj2VNOv0Jf6_xzBBrJw7s3Tg8lOeStTx6CPuRjhCYMhuM8z7FvCVKFPG4QeTGAWOoTs/s1600/esProc_inmemory_group_code_2.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><b><span lang="EN-US"><span style="font-family: inherit;">Code explanation:</span></span></b></div><div class="1" style="text-indent: 0px;"><span style="font-family: inherit;"><span style="text-indent: -0.1pt;"><b>1. </b>In this example, the grouping criterion comes from the OrderDate field. The order dates can be converted to the years with </span><i style="text-indent: -0.1pt;">year(OrderDate)</i><span style="text-indent: -0.1pt;">, then data of the same year will be grouped together.</span></span></div><div class="1" style="text-indent: 0px;"><span lang="EN-US" style="text-indent: -0.1pt;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="text-indent: 0px;"><span lang="EN-US" style="text-indent: -0.1pt;"><span style="font-family: inherit;">2. There may be more than one field for grouping data. For example, the data could be grouped by both the year and the sellerID to put records of each seller in each year into a group. Below is the code for doing it:</span></span></div><div class="1" style="text-indent: 0px;"><span lang="EN-US" style="color: #1f497d; text-indent: 21.2pt;"><span style="font-family: inherit;">A1.group(year(OrderDate),SellerId)</span></span></div><div class="1" style="text-indent: 0px;"><span lang="EN-US" style="text-indent: -0.1pt;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="text-indent: 0px;"><span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -0.1pt;">3.</span><span lang="EN-US" style="text-indent: -0.1pt;">Often, the grouped data are to be aggregated, like getting each year’s sales amount based on A2’s data. The code is:</span></span></div><div class="1" style="mso-char-indent-count: 2.02; text-indent: 21.2pt;"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A2.new(year(OrderDate):y,~.sum(Amount):a)<o:p></o:p></span></span></div><span style="font-family: inherit;"><br />
</span> <span style="font-family: inherit;">Computed result is as follows: </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOFkivzS9JIpsF7aDeKegUXE-lRZPCKzkRZYeZMJULb4alMbTeN8iUHLZOF3A4nNsbaH5jSiJCLOZJzQ75Vd-qZXV6T-bfWOhUCkQcrpR6oSCnnY6mDpsEtnWvW_7f-hm6FHKRdqbVvBU/s1600/esProc_inmemory_group_code_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOFkivzS9JIpsF7aDeKegUXE-lRZPCKzkRZYeZMJULb4alMbTeN8iUHLZOF3A4nNsbaH5jSiJCLOZJzQ75Vd-qZXV6T-bfWOhUCkQcrpR6oSCnnY6mDpsEtnWvW_7f-hm6FHKRdqbVvBU/s1600/esProc_inmemory_group_code_3.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="1"><span lang="EN-US"><span style="font-family: inherit;">Or we can combine grouping and summarizing into one step:<o:p></o:p></span></span></div><div class="MsoListParagraph" style="mso-char-indent-count: 2.02; text-indent: 21.2pt;"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A1.group(year(OrderDate):y,~.sum(Amount):a)<o:p></o:p></span></span></div><div class="1"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="1"><span lang="EN-US"><span style="font-family: inherit;">Alternatively, we can choose the <i>groups</i> function with better performance yet less flexibility:</span></span></div><div class="1"><span style="color: #1f497d; text-indent: 21.2pt;"><span style="font-family: inherit;">A1.groups(year(OrderDate):y; sum(Amount):a)</span></span></div><div class="1"><span style="text-indent: 0cm;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1"><span style="font-family: inherit;"><span style="text-indent: 0cm;">Of course, sometimes we have to perform grouping and aggregate separately in order to reuse the code and improve computational efficiency, like the scenario in which one of A2’s group needs filtering and another one requires relational computing. In another scenario, the summarized data of a certain group is unusual and worth further study, then this group can be used directly in the subsequent computations without the need of filtering it again.</span><span style="text-indent: 0cm;"> </span></span></div><div class="1"><span style="text-indent: -0.1pt;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="text-indent: 0px;"><span style="font-family: inherit;"><span style="text-indent: -0.1pt;">4. By default, esProc’s </span><i style="text-indent: -0.1pt;">group</i><span style="text-indent: -0.1pt;"> function will group data using </span><i style="text-indent: -0.1pt;">hash </i><span style="text-indent: -0.1pt;">algorithm. But for ordered data, the comparison of adjacent rows, which is equivalent to </span><i style="text-indent: -0.1pt;">merge</i><span style="text-indent: -0.1pt;"> operation, may have higher performance. This approach can be implemented by using </span><i style="text-indent: -0.1pt;">@o</i><span style="text-indent: -0.1pt;"> option with </span><i style="text-indent: -0.1pt;">group</i><span style="text-indent: -0.1pt;"> function. For example:</span></span></div><div class="1" style="margin-left: 21.2pt; mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><span lang="EN-US" style="color: #1f497d;">A1.group@o(year(OrderDate),SellerId)</span><span lang="EN-US"><o:p></o:p></span></span></div><h2><span lang="EN-US"><span style="font-family: inherit; font-size: small;">Alignment grouping<o:p></o:p></span></span></h2><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">Equal grouping groups data by the field(s) coming from within the dataset. <a href="https://www.blogger.com/null" name="OLE_LINK17"></a><a href="https://www.blogger.com/null" name="OLE_LINK5"></a><a href="https://www.blogger.com/null" name="OLE_LINK4">If the grouping criteri</a>on is one or more fields of another data set, a user-defined array, or a parameter list, etc., the grouping model will be referred as an alignment grouping. <o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">Different from the equal grouping, alignment grouping may produce empty subsets, which means no members in the original data can satisfy a certain grouping condition. It may also lead to incomplete grouping, that is, there may be members that will not appear in any group. Neither would happen with equal grouping. <o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: inherit;"><b><span lang="EN-US">Case description:</span></b><span lang="EN-US"> Group the orders table according to the list of best 10 sellers selected by KPIs. <o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="MsoNormal"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK8"></a><a href="https://www.blogger.com/null" name="OLE_LINK7"></a><a href="https://www.blogger.com/null" name="OLE_LINK6"><b><span lang="EN-US">Ungrouped data set:</span></b><span lang="EN-US"> <o:p></o:p></span></a></span></div><div class="MsoNormal"><a href="https://www.blogger.com/null" name="OLE_LINK6"><b><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></b></a></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">The orders table in the previous example will also be used here. Data is stored in A1.<o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><span style="font-family: inherit;">The best 10 sellers list is stored in B1 as follows: </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI4oZzQWvNEPBDjb5NIJ77wFMvilUxQREWvTNqAEsl6erzl3S9axmui_MwuR3yGDCQZrkHtSSf9pFGHWe-bEGobLn583MmzFxD-n-vLCRB630qbZFDYlChF4R17hMB_ERdRV0b4728aj4/s1600/esProc_inmemory_group_code_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI4oZzQWvNEPBDjb5NIJ77wFMvilUxQREWvTNqAEsl6erzl3S9axmui_MwuR3yGDCQZrkHtSSf9pFGHWe-bEGobLn583MmzFxD-n-vLCRB630qbZFDYlChF4R17hMB_ERdRV0b4728aj4/s1600/esProc_inmemory_group_code_4.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">The list of sellers may come from an intermediate table, or be generated by a piece of code. It’s not important how it is produced in this example. <o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="MsoNormal"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK10"></a><a href="https://www.blogger.com/null" name="OLE_LINK9"><b><span lang="EN-US">esProc code:<o:p></o:p></span></b></a></span></div><div class="MsoNormal"><a href="https://www.blogger.com/null" name="OLE_LINK9"><b><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></b></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK27"></a><a href="https://www.blogger.com/null" name="OLE_LINK26"><span lang="EN-US" style="color: #1f497d;">A1.align@a(B1:empID,SellerId)</span></a><span lang="EN-US" style="color: #1f497d;"><o:p></o:p></span></span></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK26"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;"><br />
</span></span></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK12"></a></span></div><span style="font-family: inherit;"><a href="https://www.blogger.com/null" name="OLE_LINK11" style="text-indent: 0cm;"><b><span lang="EN-US">Computed result:</span></b></a> </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhADeKROHqcI_tMz6oLqQ9TgegVAOsQKbAjr-pkRw-YTWJBCAzjKcXgw26C42nGY28jJdNZnXk38ugr_tSBSasfrv0MeAO33nN_1Z9G_GcydIxkoLAKgjCDVVswqp6zkPYWfK0pTsb_rPw/s1600/esProc_inmemory_group_code_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhADeKROHqcI_tMz6oLqQ9TgegVAOsQKbAjr-pkRw-YTWJBCAzjKcXgw26C42nGY28jJdNZnXk38ugr_tSBSasfrv0MeAO33nN_1Z9G_GcydIxkoLAKgjCDVVswqp6zkPYWfK0pTsb_rPw/s1600/esProc_inmemory_group_code_5.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><b><span lang="EN-US"><span style="font-family: inherit;">Code explanation:</span></span></b></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK13" style="text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK13" style="text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><b>1. </b>In this example, the grouping criterion (list of sellers) is outside of the data set being grouped. After data is grouped, each group contains only the data of one seller, and groups are arranged according to the order of members in the sellers list. </span></span></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK28" style="text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></a></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><a href="https://www.blogger.com/null" name="OLE_LINK28" style="text-indent: 0cm;"><span lang="EN-US"><span style="font-family: inherit;">2. Because sellers in the orders table outnumber the best sellers, some of the orders will not appear in any group. We can use function option <i>@n</i> to store those orders in one additional group, as shown below:</span></span></a></div><span style="font-family: inherit;"> </span><div class="1"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A1.align@a@n(B1:empID,SellerId)<o:p></o:p></span></span></div><div class="1"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;"><br />
</span></span></div><span style="font-family: inherit;">This group will be put in the end: </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgi0lZZfyh2JWlyCAwev9RSijt0QnCO7EACh9_nvryg5axlneAzAiJKqf5LkvCqIulGg_Rr0tdT8pGt8Kt0piaxFQ8KD2shDr6Dky-snKF5kTtIMEbthPkEBW491MOsiWwcZXMOalUSpGk/s1600/esProc_inmemory_group_code_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgi0lZZfyh2JWlyCAwev9RSijt0QnCO7EACh9_nvryg5axlneAzAiJKqf5LkvCqIulGg_Rr0tdT8pGt8Kt0piaxFQ8KD2shDr6Dky-snKF5kTtIMEbthPkEBW491MOsiWwcZXMOalUSpGk/s1600/esProc_inmemory_group_code_6.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <span style="font-family: inherit;">3. Sometimes not all members of the grouping criterion will fall in the data set to be grouped. For instance, the grouping criterion is “a list of newly-employed sellers”. In this case, it’s normal to produce empty groups. If we modify the first record of the list into <i>empID=100</i>, the result will be: </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1h4mGjUH0ga9drFjZtYRjm8j1FziMiURhXLpJ6PzcSrAjn8YIKh8GxF-U1RNvQ2nP2TBNFjZRFLQaB4UwG-TGkGarUQrP5GeLvQPePTbgM1-0gr4t6jEjon8LaQKsGwOl9tEVW80x1YQ/s1600/esProc_inmemory_group_code_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1h4mGjUH0ga9drFjZtYRjm8j1FziMiURhXLpJ6PzcSrAjn8YIKh8GxF-U1RNvQ2nP2TBNFjZRFLQaB4UwG-TGkGarUQrP5GeLvQPePTbgM1-0gr4t6jEjon8LaQKsGwOl9tEVW80x1YQ/s1600/esProc_inmemory_group_code_7.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <h2><span lang="EN-US"><span style="font-family: inherit; font-size: small;">Enumeration grouping <o:p></o:p></span></span></h2><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">The grouping criterion for enumeration grouping is even more flexible. It could be any boolean expression. The records satisfying the value of the expression will be put into the same group. <o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">Similar to alignment grouping, this is also the incomplete grouping as it probably produces empty subsets or a result in which some members are not included in any group. Moreover, this type of grouping may have the result that certain members appear in more than one group. <o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: inherit;"><b><span lang="EN-US">Case description:</span></b><span lang="EN-US"> Dividing orders into four groups, they are: A. order amount is less than 1,000; B. order amount is less than 2,000; C. order amount is less than 3,000; D. order amount is less than 10,000. Special requirement: data cannot be grouped repeatedly, that is, if an order has been in group A, it must not be put into group B, C, or D. <o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="MsoNormal"><b><span lang="EN-US"><span style="font-family: inherit;">Ungrouped data set: <o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></b></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;">The orders table in previous examples will still be used. Data is stored in A1. <o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></div><div class="MsoNormal"><b><span lang="EN-US"><span style="font-family: inherit;">esProc code:<o:p></o:p></span></span></b></div><div class="MsoNormal"><b><span lang="EN-US"><span style="font-family: inherit;"><br />
</span></span></b></div><div class="MsoNormal"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A2=["?<=1000","?<=2000","?<=3000","?<=10000"]<o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;">A3=A1.enum(A2,Amount)<o:p></o:p></span></span></div><div class="MsoNormal"><span lang="EN-US" style="color: #1f497d;"><span style="font-family: inherit;"><br />
</span></span></div><span style="font-family: inherit;"><b style="text-indent: 0cm;"><span lang="EN-US">Computed result:</span></b> </span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixHJ5hPbuxFFeDa0usKS8xCTf8p3dmx67WtahZsPQfXnLWH_0NuQwupl4efTnsyb5Tv4OLxqXv_wfZRKWoL_zBH58yzL5EtkvQIy_CHvfEz8Se4iEB7SjY7bl5n7M68NIh9QZiYfLd6q0/s1600/esProc_inmemory_group_code_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixHJ5hPbuxFFeDa0usKS8xCTf8p3dmx67WtahZsPQfXnLWH_0NuQwupl4efTnsyb5Tv4OLxqXv_wfZRKWoL_zBH58yzL5EtkvQIy_CHvfEz8Se4iEB7SjY7bl5n7M68NIh9QZiYfLd6q0/s1600/esProc_inmemory_group_code_8.jpg" /></span></a></div><span style="font-family: inherit;"><br />
</span> <div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><b><span lang="EN-US"><span style="font-family: inherit;">Case explanation:</span></span></b></div><div class="1" style="mso-char-indent-count: 0; text-indent: 0cm;"><span style="text-indent: -29.25pt;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="text-indent: 0px;"><span style="text-indent: -29.25pt;"><span style="font-family: inherit;"><b>1.</b>In this example, grouping criteria are multiple flexible expressions. Each record will be compared with each of the expressions. Those records that can match the same expression will be put into the same group. Groups are arranged according to the order of the grouping criteria as well.</span></span></div><div class="1" style="text-indent: 0px;"><span lang="EN-US" style="text-indent: -29.25pt;"><span style="font-family: inherit;"><br />
</span></span></div><div class="1" style="text-indent: 0px;"><span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -29.25pt;">2.By default, enumeration grouping will not produce duplicate members in the result. Because after group A’s data is selected out, expression B will be matched with the rest of the records, as this example has shown so far. But the use of function option <i>@r</i> allows us to match expression B with all records, which will produce duplicate members. For example the result of <span style="color: #1f497d;">A3=A1.enum@r(A2,Amount)</span> is as follows:</span> </span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSqEW3hFfh63UiHD8AfQ934KES2YSfPblaojUKtLhWbHnu6F6Wchr-yr5T0gW7jcCh29jOxbktBBQENErHBlsov1gHd5WfodznWzH6MQ4h8ssUH_FozAYTFaklC9j7DGHeY7l0qTzBWoc/s1600/esProc_inmemory_group_code_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSqEW3hFfh63UiHD8AfQ934KES2YSfPblaojUKtLhWbHnu6F6Wchr-yr5T0gW7jcCh29jOxbktBBQENErHBlsov1gHd5WfodznWzH6MQ4h8ssUH_FozAYTFaklC9j7DGHeY7l0qTzBWoc/s1600/esProc_inmemory_group_code_9.jpg" /></span></a></div><div class="separator" style="clear: both; text-align: left;"><span lang="EN-US" style="text-indent: -29.25pt;"><span style="font-stretch: normal;"><span style="font-family: inherit;"><br />
</span></span></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -29.25pt;"><span style="font-stretch: normal;">3. </span></span><span lang="EN-US" style="text-indent: -29.25pt;">Likewise, if values of an enumeration expression fall outside of the data to be grouped, it will correspond to an empty group. Besides, if certain records cannot match any expression, function option <i>@n</i> can be used to group these surplus records together. </span></span></div>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-19880261396892809942015-09-14T06:02:00.002-05:002015-09-14T06:03:44.895-05:00Code Examples of esProc Foreign Key Function<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">If <i>k</i> (a single field or a
combination of fields) is table <i>M</i>’s primary key, and <i>k</i>, at the
same time, exists in table <i>B</i>, then <i>k</i> is regarded as B’s foreign
key. The foreign key defines a relationship between two tables and is one of
the most important concepts for structured data computing. Through object
references, esProc makes foreign key easy to function. The following examples
aim to illustrate the how foreign key is used in esProc.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><b><span lang="EN-US">Example 1 Associate a referenced table and a
referencing table </span></b><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><i><span lang="EN-US">Order </span></i><span lang="EN-US">(containing orders information)</span><span lang="EN-US"> is the referencing table, <i>emp</i>(containing employee information) is the referenced table. It is
required to connect <i>emp</i> with <i>order </i>and display <i>emp</i>’s Name field, Gender field and Salary
field and <i>order</i>’s OrderID field and Amount field in the result table. <o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<span lang="EN-US" style="font-family: inherit; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;">Note: Besides <i>emp</i> table and <i>order</i> table used
here, <i>dep</i> table (containing departments information) is to be used in subsequent
examples. The relationship between <i>emp</i>
and <i>order</i>/<i>dep</i> through the foreign key is shown as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiJq_zG8_Ho4QQRDr9e2QYpAzWBmzoXtTsy9qcnQSlsfMcsLaARNyMj5tHp6cDygGqOj537kzLix0b98pBSosfRyGhiGZR6DrSxNNqIX2Bl9s4VknzgqwtCYkYJjuY1lI-VgDKpQPa70o/s1600/esProc_inmemory_foreign_key_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiJq_zG8_Ho4QQRDr9e2QYpAzWBmzoXtTsy9qcnQSlsfMcsLaARNyMj5tHp6cDygGqOj537kzLix0b98pBSosfRyGhiGZR6DrSxNNqIX2Bl9s4VknzgqwtCYkYJjuY1lI-VgDKpQPa70o/s1600/esProc_inmemory_foreign_key_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Data may
originate from databases or text files. For example:<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> order=esProc.query("select
OrderID,SellerId,Amount,OrderDate from sales")<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> emp=esProc.query("select
EId,Name,Gender,Birthday,Dept,Salary from emp")<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> dep=esProc.query("select
* from department")<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;"><br /></span></b></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">esProc
code for doing this:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A3=order.switch(SellerId, emp:EId)<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A4=order.new(<a href="https://www.blogger.com/null" name="OLE_LINK8">OrderID,Amount</a>,<a href="https://www.blogger.com/null" name="OLE_LINK11"></a><a href="https://www.blogger.com/null" name="OLE_LINK10">SellerId.</a><a href="https://www.blogger.com/null" name="OLE_LINK9">Name,SellerId.Gender,SellerId.Salary</a>)<o:p></o:p></span></div>
<span style="font-family: inherit;"><b><span lang="EN-US"><br /></span></b>
<b><span lang="EN-US">Computed result:</span></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEictgz-7OEKFtISWOG5vuyqUIrB6CScoVHwGWdygeSlBa_rHH8XUsz8Ag2AJSGBpfFwibmIOGraMHkP2pqvVKQ9qyBhTDgIg7S9PnvSogMMBQGU73yYNe10Y4u9gKP6P4oyGdKWweP3H7o/s1600/esProc_inmemory_foreign_key_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEictgz-7OEKFtISWOG5vuyqUIrB6CScoVHwGWdygeSlBa_rHH8XUsz8Ag2AJSGBpfFwibmIOGraMHkP2pqvVKQ9qyBhTDgIg7S9PnvSogMMBQGU73yYNe10Y4u9gKP6P4oyGdKWweP3H7o/s1600/esProc_inmemory_foreign_key_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span style="font-family: inherit;"><b><span lang="EN-US">Code explanation:</span></b><span lang="EN-US"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;"><br /></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">A3: Replace records of <i>order</i>’s SellerID with their corresponding
ones in <i>emp</i> to create a foreign key relationship between the two
tables. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">A4: Get OrderID field and Amount field from
<i>order</i>, and get Name, Gender and Salary field from <i>emp</i> through foreign
key references. We can see that, with object references, fields in <i>emp</i>
can be accessed directly from <i>order, </i>thus saving us the trouble of
writing complex and difficult <i>join</i> statements. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">Example 2: Query referencing table according to
condition existing in referenced table <o:p></o:p></span></b></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;"><br /></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Find orders
signed by female sellers whose salary is greater than 10,000. <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">esProc
code for doing this:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A3=order.switch(SellerId, emp:EId) / the same as above example<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="color: #1f497d;"> A5=</span><span lang="EN-US" style="color: #1f497d; mso-font-kerning: 0pt;">order.select(SellerId.Salary>10000
&& SellerId.Gender=="F")</span><span lang="EN-US" style="color: #1f497d;"><o:p></o:p></span></span></div>
<span style="font-family: inherit;"><b><span lang="EN-US"><br /></span></b>
<b><span lang="EN-US">Computed results:</span></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi49CFobZQ9jrnc0cR1JU6uxE4glUM_fgv9C8FUoOZQsO1_ZthUqWJkJEr85NtnomArKna21jpcefsV4b81oda3yEy8-7tVneyl9gzdto4HVSOhn1AdarrDhO30fowosOuQ5m1P8WXO3Sw/s1600/esProc_inmemory_foreign_key_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi49CFobZQ9jrnc0cR1JU6uxE4glUM_fgv9C8FUoOZQsO1_ZthUqWJkJEr85NtnomArKna21jpcefsV4b81oda3yEy8-7tVneyl9gzdto4HVSOhn1AdarrDhO30fowosOuQ5m1P8WXO3Sw/s1600/esProc_inmemory_foreign_key_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Click the above hyperlinks in
blue and corresponding employee information will be shown:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVLThtUpWUd7Qjq6s8OT4WyCSrU9Cr5aaZZbEguxlWwlw6n50n5dyFiQPx-0y5iZpMNu5QjaUqrlkDf8glkvV2MzYYKkIO_V89iSQXdQ2Q37IdFFBOV2Y-sXHHnqajDdmWq0ho9Tj7f54/s1600/esProc_inmemory_foreign_key_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVLThtUpWUd7Qjq6s8OT4WyCSrU9Cr5aaZZbEguxlWwlw6n50n5dyFiQPx-0y5iZpMNu5QjaUqrlkDf8glkvV2MzYYKkIO_V89iSQXdQ2Q37IdFFBOV2Y-sXHHnqajDdmWq0ho9Tj7f54/s1600/esProc_inmemory_foreign_key_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">Example 3: Group data
according to referenced table <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Compute sales amount of each department.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;"><br /></span></b></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">esProc
code for doing this:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A3=order.switch(SellerId, emp:EId) /<a href="https://www.blogger.com/null" name="OLE_LINK2"></a><a href="https://www.blogger.com/null" name="OLE_LINK1"> the same as above
example</a><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="color: #1f497d;"> A5</span><span lang="EN-US" style="color: #1f497d; mso-font-kerning: 0pt;">=order.groups(SellerId.Dept;sum(Amount))<o:p></o:p></span></span></div>
<span style="font-family: inherit;"><b><span lang="EN-US" style="font-family: "Calibri","sans-serif"; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;"><br /></span></b>
<b><span lang="EN-US" style="font-family: "Calibri","sans-serif"; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;">Computed results:</span></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-vWLwkgk_yZcClCgVge5NRR6JIZDUnSpjCViNKStaSHE5t_Fll5L7J1fC_0pcoQwTHqTycRepppQ6bRpJ2Es7i9oMK6ZTStHYeK3WZyM0VVhoYHvlYVW7_MqxyRDmhzVQma2p-rBw3Wc/s1600/esProc_inmemory_foreign_key_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-vWLwkgk_yZcClCgVge5NRR6JIZDUnSpjCViNKStaSHE5t_Fll5L7J1fC_0pcoQwTHqTycRepppQ6bRpJ2Es7i9oMK6ZTStHYeK3WZyM0VVhoYHvlYVW7_MqxyRDmhzVQma2p-rBw3Wc/s1600/esProc_inmemory_foreign_key_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span lang="EN-US">You can rename
fields, like </span><span lang="EN-US" style="color: #1f497d;">order.groups(SellerId.Dept:dt;sum(Amount):amt)</span><span lang="EN-US">. The effect of name changing is shown
below:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwWTMAg9yh1R1RoEAysayuJ3JSqIgSZN6dzBJJfEfDLsWxx5ptEX4DhXh28lcI6pHjXbP8k77al7q06uLw23f5Hv6DZuF4mnASX8tHD0b2FwSKElCCMC2oM1GwIDdxvdNJbztYNQjIjdw/s1600/esProc_inmemory_foreign_key_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwWTMAg9yh1R1RoEAysayuJ3JSqIgSZN6dzBJJfEfDLsWxx5ptEX4DhXh28lcI6pHjXbP8k77al7q06uLw23f5Hv6DZuF4mnASX8tHD0b2FwSKElCCMC2oM1GwIDdxvdNJbztYNQjIjdw/s1600/esProc_inmemory_foreign_key_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">Example 4: Complex
association between multiple tables<o:p></o:p></span></b></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Find
managers of departments whose sales amount is greater than 50,000. <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit; font-size: 11.0pt; mso-bidi-font-size: 12.0pt;"><br /></span></b></div>
<div class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit; font-size: 11.0pt; mso-bidi-font-size: 12.0pt;">esProc code for doing this:<o:p></o:p></span></b></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A3=order.switch(SellerId,
emp:EId) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A4=dep.switch(Manager,emp:EId) <o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A5=emp.switch(Dept,dep:DeptNo)<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A6=order.groups(SellerId.Dept:dt;sum(Amount):amt)<o:p></o:p></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="color: #1f497d; font-family: inherit;"> A7=A6.select(amt<=50000).(dt).(Manager).(Name)<o:p></o:p></span></div>
<span style="font-family: inherit;"><b><span lang="EN-US" style="font-family: "Calibri","sans-serif"; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;"><br /></span></b>
<b><span lang="EN-US" style="font-family: "Calibri","sans-serif"; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;">Computed results:</span></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8epafxb7nER2HV5YjPmKk1MBqdp6Pwvw8a4PbEgXLdbHjs1mn1cpYG9Kt4hx2uvzizZpHsIc7H6SlIrd60nliEc_V2ttoTXdDLIxP01oE78q1wts3BryeG_lCKVI-DFlcdX90po_Shm8/s1600/esProc_inmemory_foreign_key_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8epafxb7nER2HV5YjPmKk1MBqdp6Pwvw8a4PbEgXLdbHjs1mn1cpYG9Kt4hx2uvzizZpHsIc7H6SlIrd60nliEc_V2ttoTXdDLIxP01oE78q1wts3BryeG_lCKVI-DFlcdX90po_Shm8/s1600/esProc_inmemory_foreign_key_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div align="left" class="MsoNormal">
<b><span lang="EN-US" style="font-family: inherit;">Code explanation:<o:p></o:p></span></b></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">A3, A4,
A5</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri;">:</span><span lang="EN-US">Create complete foreign key relationships.<o:p></o:p></span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;">A6: Compute sales amount of each department (See above
example). The result is:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh_yCqSNea4B-RTFS4p_uxwxl2HDm5AuWURZl_4VqGWRR1L5yzNmVBDUJ4GgplPu-ZQZXQWGigIZ0a6_ZTdjqc9o-QsGGRcDnEesyS9qE4_Az4ujt9UvH7bdNDEybXgjX2Ov3ShJvhblg/s1600/esProc_inmemory_foreign_key_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh_yCqSNea4B-RTFS4p_uxwxl2HDm5AuWURZl_4VqGWRR1L5yzNmVBDUJ4GgplPu-ZQZXQWGigIZ0a6_ZTdjqc9o-QsGGRcDnEesyS9qE4_Az4ujt9UvH7bdNDEybXgjX2Ov3ShJvhblg/s1600/esProc_inmemory_foreign_key_8.jpg" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: inherit;"><br /></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">A7</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri;">:</span><span lang="EN-US">Use object references to solve the problem intuitionally. Expression
<span style="color: #1f497d;">A6.select(amt<=50000).(dt).(Manager).(Name) </span>can
be divided into four steps according to full stops. They are:</span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; text-indent: -21pt;"><br /></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -21pt;">1. </span><span lang="EN-US" style="text-indent: -21pt;">Find records whose sales amount
is greater than 50,000 from A6.</span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; text-indent: -21pt;"><br /></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -21pt;">2<span style="font-stretch: normal;">. </span></span><span lang="EN-US" style="text-indent: -21pt;">Get records corresponding to those
in <i>dt</i> field (from <i>dep </i>table)</span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; text-indent: -21pt;"><br /></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -21pt;">3<span style="font-stretch: normal;">.
</span></span><span lang="EN-US" style="text-indent: -21pt;">Get records corresponding to those
in <i>Manager</i> field (from <i>emp </i>table)</span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; text-indent: -21pt;"><br /></span></div>
<div align="left" class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -21pt;">4<span style="font-stretch: normal;">.
</span></span><span lang="EN-US" style="text-indent: -21pt;">Get<i> Name</i> field.</span></span></div>
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; text-indent: -21pt;"><br /></span></div>
<span style="font-family: inherit;">Details are as follows:</span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span style="color: #1f497d;">A6.select(amt<=50000)</span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWqUruyLFRnapTj8r9JNi4D5qlzQOY87pjN6nRDx6IRj1PUGaVtOtTLyN1qXsZ7zrWPOsj8Z6KLLWtl9UFTw23FxM-s7UVjr0zslZP5oe-m4GDFnqxnxUpk3ey1Y2WQfTuQW2KeU-JIi8/s1600/esProc_inmemory_foreign_key_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWqUruyLFRnapTj8r9JNi4D5qlzQOY87pjN6nRDx6IRj1PUGaVtOtTLyN1qXsZ7zrWPOsj8Z6KLLWtl9UFTw23FxM-s7UVjr0zslZP5oe-m4GDFnqxnxUpk3ey1Y2WQfTuQW2KeU-JIi8/s1600/esProc_inmemory_foreign_key_9.jpg" /></a></span></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span style="color: #1f497d;">.(dt)</span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsSyzihw7gAYuIulHRHtkC3VZ9YJYBmfXocKWBBXTdbnG3PgM7rD3FWWFTacr1DzpUi1To5ZpAqWBFCZY0OwQHhqlfHXl4SsYay3mUfZCjdM1WGWscIdm2jIILPYyEZrnUzNWreRenD_c/s1600/esProc_inmemory_foreign_key_10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsSyzihw7gAYuIulHRHtkC3VZ9YJYBmfXocKWBBXTdbnG3PgM7rD3FWWFTacr1DzpUi1To5ZpAqWBFCZY0OwQHhqlfHXl4SsYay3mUfZCjdM1WGWscIdm2jIILPYyEZrnUzNWreRenD_c/s1600/esProc_inmemory_foreign_key_10.jpg" /></a></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span style="color: #1f497d;">.(Manager)</span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicelFiB_A7K6mNnBqiwim_AT_kTWOSO9acaFnfNJrr92VWdCnlzKYzRCJdTeD8yuo1rX5cz8n6xqthoMmUkPn8U7ALxIE1Qs0fS2WcrGjETR6hZcXb-XRmbVdjyVZqcMBsp8WUSXyC39g/s1600/esProc_inmemory_foreign_key_11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicelFiB_A7K6mNnBqiwim_AT_kTWOSO9acaFnfNJrr92VWdCnlzKYzRCJdTeD8yuo1rX5cz8n6xqthoMmUkPn8U7ALxIE1Qs0fS2WcrGjETR6hZcXb-XRmbVdjyVZqcMBsp8WUSXyC39g/s1600/esProc_inmemory_foreign_key_11.jpg" /></a></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span style="color: #1f497d;">.(Name)</span><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVmT4ilH6jVvpwg9biE1GaFn4LebFQK2DeMkT5r3UBK-l5NDWlX9KbtOYaUOnSeEr0E2CwjrAchi0V0BNGIiR9EOWUXg_Pb4KbQvXVplkec6L5r91It2lAH5_eumwXewN9GYAPny4tjxQ/s1600/esProc_inmemory_foreign_key_12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVmT4ilH6jVvpwg9biE1GaFn4LebFQK2DeMkT5r3UBK-l5NDWlX9KbtOYaUOnSeEr0E2CwjrAchi0V0BNGIiR9EOWUXg_Pb4KbQvXVplkec6L5r91It2lAH5_eumwXewN9GYAPny4tjxQ/s1600/esProc_inmemory_foreign_key_12.jpg" /></a></span></div>
<span lang="EN-US" style="font-family: "Calibri","sans-serif"; font-size: 10.5pt; mso-ansi-language: EN-US; mso-bidi-font-family: 黑体; mso-bidi-font-size: 11.0pt; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体; mso-fareast-language: ZH-CN; mso-font-kerning: 1.0pt;"><br /></span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-51227269287546489812015-09-11T08:30:00.000-05:002015-09-11T08:30:01.686-05:00An Example of esProc Set Operations<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">There are a lot of occasions when set operations are needed to do
structured data summarizing and analysis. For example, to list all students who
have published papers, find the employees who have participated in all trainings
and select students who passed the examination for the re-examination. esProc uses
sets everywhere. Its most commonly used data types, such as sequences and table
sequences, are all sets. Therefore, a better understanding and manipulation of sets
helps to perform data computing in a more reasonable and faster way. <o:p></o:p></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<br />
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">For example, the table below contains sales data:<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2sWW1ET8Igc_ZWV0FQkOdgAVKz_hOVTUOfOywgFn9-JlFzf_QgRlKBv1eET4NscGKGR1PNIybXpWlqv3vlijr-OMefHBw1YDxhXzRCIDWesbTH4e6TjgPBiV-XRG5mk8xGaWeHxi_8w/s1600/esProc_inmemory_set_operation_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU2sWW1ET8Igc_ZWV0FQkOdgAVKz_hOVTUOfOywgFn9-JlFzf_QgRlKBv1eET4NscGKGR1PNIybXpWlqv3vlijr-OMefHBw1YDxhXzRCIDWesbTH4e6TjgPBiV-XRG5mk8xGaWeHxi_8w/s1600/esProc_inmemory_set_operation_1.jpg" /></a></div>
<br />
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">We are to find the clients whose monthly sales amount is always in
the top 20 in 2013. To do this we need to first retrieve the 2013 sales data, group
it by the month, then select the top 20 clients of each month by loops and
finally get the result by performing intersection. It is too difficult to
handle such a complex problem in either SQL or the stored procedure. <o:p></o:p></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<span style="text-indent: 0cm;">esProc handles a complex problem by splitting it into different
steps, and gets the final result step by step. First, from the sales data we
retrieve that of 2013 and group it by the month:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizx7D4cu44FlV5OfBeBRZZ9dx4gqHp7IJowW066rozdxp74EHdXolfRO43p0koMPsYuEPewis3C0uXm0kc-FWHHaox2kOk2X8oG7b5URLBvUXsHYerzbd-YChP3Jgm_vHNWDEahxA6KEs/s1600/esProc_inmemory_set_operation_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizx7D4cu44FlV5OfBeBRZZ9dx4gqHp7IJowW066rozdxp74EHdXolfRO43p0koMPsYuEPewis3C0uXm0kc-FWHHaox2kOk2X8oG7b5URLBvUXsHYerzbd-YChP3Jgm_vHNWDEahxA6KEs/s1600/esProc_inmemory_set_operation_2.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">esProc performs </span><b style="text-indent: 0cm;">veritable data
grouping</b><span style="text-indent: 0cm;"> by dividing data into multiple sets as required. This is different
from SQL "group by" command, which returns only the aggregate results.
The grouping result of A3 is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjURRW-WuCEwVWTaKSBVzCM2n4qR3EOj_0O_8FIZBuGQZzlcsldrNUORCQzP1pbgf9EByN4ktOUgnr4TvJgSSUydXQQqnHWrNRzpJmVMkND7asNpBGafhgH1hjthgExG_ga8GJq3Fb2zQQ/s1600/esProc_inmemory_set_operation_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjURRW-WuCEwVWTaKSBVzCM2n4qR3EOj_0O_8FIZBuGQZzlcsldrNUORCQzP1pbgf9EByN4ktOUgnr4TvJgSSUydXQQqnHWrNRzpJmVMkND7asNpBGafhgH1hjthgExG_ga8GJq3Fb2zQQ/s1600/esProc_inmemory_set_operation_3.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">Data has been automatically sorted before it is grouped. Each group
is a set of sales records. Below are the records of March:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_lb-uwjjqJDIOgNxaKoqUBwHNDHpa4ZsTj1rYD2HA9Svh3tbCbXZSFmgJBoKCMOXt_gKw6yV7ynUafGnsI_J90nUfAml2wSrDp7GYQxE0l6P0EWfb36o91CLy-8EmS0t74ZTi0PJyeso/s1600/esProc_inmemory_set_operation_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_lb-uwjjqJDIOgNxaKoqUBwHNDHpa4ZsTj1rYD2HA9Svh3tbCbXZSFmgJBoKCMOXt_gKw6yV7ynUafGnsI_J90nUfAml2wSrDp7GYQxE0l6P0EWfb36o91CLy-8EmS0t74ZTi0PJyeso/s1600/esProc_inmemory_set_operation_4.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">To know the total sales amount of each client in each month, we need
to group the data by clients. In esProc, we just loop through data of every month
and group it by customers. We can use </span><i style="text-indent: 0cm;">A.(x)</i><span style="text-indent: 0cm;">
to loop through set members without the need to write loop code.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPvzCRkjQFq7wTPiDXstjMhQsO8vhjHamj5gujxD6YvEHQ4A1hAKMTukywpTS9cRdOaqHK1pOyt1PGyv6WnWniTSflyqjZp-1uw2_sH7CYGPN9iMLaAG_-gL6XrIdyHiBF-Tj1qzNqXn0/s1600/esProc_inmemory_set_operation_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPvzCRkjQFq7wTPiDXstjMhQsO8vhjHamj5gujxD6YvEHQ4A1hAKMTukywpTS9cRdOaqHK1pOyt1PGyv6WnWniTSflyqjZp-1uw2_sH7CYGPN9iMLaAG_-gL6XrIdyHiBF-Tj1qzNqXn0/s1600/esProc_inmemory_set_operation_5.jpg" /></a></div>
<br />
<span lang="EN-US" style="text-indent: 0cm;">After the second grouping, in A4 every month’s data is a <b>set of sets</b></span><span style="font-family: 宋体; text-indent: 0cm;">:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2cSjlCOxeeTKGKV6wXbxxTF250fsgqwFdOee0gbb8vdCiMsf9STdSxmqeuL1AL84QzRMc8pmVzNx58Ps-x4dWmWxpakQs6Vko9hD9Dgjm8p435HhAmSHfAMr1AZjwkkvkNqej3SaANrU/s1600/esProc_inmemory_set_operation_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2cSjlCOxeeTKGKV6wXbxxTF250fsgqwFdOee0gbb8vdCiMsf9STdSxmqeuL1AL84QzRMc8pmVzNx58Ps-x4dWmWxpakQs6Vko9hD9Dgjm8p435HhAmSHfAMr1AZjwkkvkNqej3SaANrU/s1600/esProc_inmemory_set_operation_6.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">Now, the data of March is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIaN8oFkoJk_jzAPSmYsZZx7Xeht1pN6eNbpcgiwuAHCDZMp_TMHDy0-vsZfCKosC5BoxJmPcihA_BGhSA-7kykryYJIqud_om3dVAzg_5gZo28bEXY6733a4rIgdEK56dNz2JIj6tMJM/s1600/esProc_inmemory_set_operation_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIaN8oFkoJk_jzAPSmYsZZx7Xeht1pN6eNbpcgiwuAHCDZMp_TMHDy0-vsZfCKosC5BoxJmPcihA_BGhSA-7kykryYJIqud_om3dVAzg_5gZo28bEXY6733a4rIgdEK56dNz2JIj6tMJM/s1600/esProc_inmemory_set_operation_7.jpg" /></a></div>
<br />
<div class="T-ParCxSpFirst" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">We can see that each subgroup in March’s data is a set of
transaction records of a certain client. <o:p></o:p></span></div>
<div class="T-ParCxSpMiddle" style="mso-char-indent-count: 0; text-indent: 0cm;">
<br /></div>
<span style="text-indent: 0cm;">The set used in esProc is different from that in mathematical concept.
esProc sets are ordered and therefore, based on them, sorting, selection by
positions and other statistical operations can be performed. Then let’s find
the top 20 clients of each month:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTrFMV0ynZyyMfgEcwuZfwMq4BoR4G0fulGn9YS8I6iPPpBdxexikONmc4bNhyphenhyphenfYdC_lBr_99Sxvv-upvktFnO_VUciM5npKRB3c8X8rD_Bsh0ymxm1Fu8d4Ydgnj8_xSCmV57TX4H2xo/s1600/esProc_inmemory_set_operation_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTrFMV0ynZyyMfgEcwuZfwMq4BoR4G0fulGn9YS8I6iPPpBdxexikONmc4bNhyphenhyphenfYdC_lBr_99Sxvv-upvktFnO_VUciM5npKRB3c8X8rD_Bsh0ymxm1Fu8d4Ydgnj8_xSCmV57TX4H2xo/s1600/esProc_inmemory_set_operation_8.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">A5 loops through each month’s data to get records of the top 20 clients
of each month. A6 lists their names and monthly sales amount. The result of A6 is
as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKqax0tylnHPfaCfImQx2eybubBP40ZEBgIEjLkoaFncDsZRNUTNNut4adDsJpE8vBNzDkSg2DhVscHa5zSMTzLf5z1mZ0JogtFrg6knUfEnAIyo0wn4NNRacDd0OHm5M_pB3OoOYSlig/s1600/esProc_inmemory_set_operation_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKqax0tylnHPfaCfImQx2eybubBP40ZEBgIEjLkoaFncDsZRNUTNNut4adDsJpE8vBNzDkSg2DhVscHa5zSMTzLf5z1mZ0JogtFrg6knUfEnAIyo0wn4NNRacDd0OHm5M_pB3OoOYSlig/s1600/esProc_inmemory_set_operation_9.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">Now it’s time to get the final result:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtMZhfCkVURxm4sOG70jVFhr_haRp7X2SMnu6usxBA0ppD6SDloEjmWr4z63HWHeDBeux8IFa-Avgb9ZMLLJFAm8R8gh6IKOkZUng_fN5E87qto1OnagbZm9im4JVoPrvg9ARlLi0nS_I/s1600/esProc_inmemory_set_operation_10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtMZhfCkVURxm4sOG70jVFhr_haRp7X2SMnu6usxBA0ppD6SDloEjmWr4z63HWHeDBeux8IFa-Avgb9ZMLLJFAm8R8gh6IKOkZUng_fN5E87qto1OnagbZm9im4JVoPrvg9ARlLi0nS_I/s1600/esProc_inmemory_set_operation_10.jpg" /></a></div>
<br />
<span style="text-indent: 0cm;">List names of the top 20 clients of every month in A7 and, finally,
get the intersection of the 12 groups of top 20 names in A8:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Ye4jJSb-hX7WAMqKSWCGTNkgZZ4qCwEaCKMlxkHvuZ4fTiBswk_RmaaQUgMFYiz8M-Y495B7PxBW3k-gOE3UaZvaFXFwcpYiiLU_aAJlyVH7t7lGwdz7850jhyphenhyphenDg6Nwa5VRedDe-BTk/s1600/esProc_inmemory_set_operation_11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Ye4jJSb-hX7WAMqKSWCGTNkgZZ4qCwEaCKMlxkHvuZ4fTiBswk_RmaaQUgMFYiz8M-Y495B7PxBW3k-gOE3UaZvaFXFwcpYiiLU_aAJlyVH7t7lGwdz7850jhyphenhyphenDg6Nwa5VRedDe-BTk/s1600/esProc_inmemory_set_operation_11.jpg" /></a></div>
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"><br /></span></div>
<div class="T-ParCxSpLast" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US"></span></div>
<div class="T-Par" style="mso-char-indent-count: 0; text-indent: 0cm;">
<span lang="EN-US">From this example we can see that esProc ordered sets make the
problem-solving more intuitive. With sets, we can easily perform grouping,
sorting and other computations, making each step of data processing focused and
easy to understand. Moreover, the use of set concept can reduce the complexity
and coding workload of loop operation as well as the set operations like intersection. <o:p></o:p></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-54479429793320701572015-09-10T08:08:00.000-05:002015-09-10T08:08:00.197-05:00Preparing Test Data with esProc <div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Test data preparation is a critical work in
software testing. High-quality test data can better simulate the business case.
It helps to meet the testing requirements by timely and effective evaluation of
software performance, or finding potential issues in the software builds. Most
of the time, the amount of data used in testing is relatively large, and the
data needs to be randomly generated according to specific requirements.
Sometimes there is certain relationship between the data, and there is the need
to retrieve data from an existing database. Therefore, the preparation of test
data often means complexity and and huge workload.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">esProc is a handy tool for test data preparation.
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">Now we need to prepare the test data for employee’s
information in text format, including employee number, name, gender, date of
birth, city and state of residence, etc. Through this example, we can understand
the way test data are being prepared.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">We have the following requirements for test
data: the employee numbers are generated sequentially. Name and gender are randomly
generated. Birthdays are randomly generated, however we need to ensure that the
current age of the employees are between 18 to 55 years old. City and states are
randomly obtained from a table in database.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;">In 3 text files Top100MaleNames.txt, Top100FemaleNames.txt
and Top100Surnames.txt, there are 100 most used male and female names, and
surnames stored.</span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWu1maH-9eVI_b8f2emsr-fIopK4HKKeQt-6tUX2g_mwz9KpT0MkDRvr2-BTfunlVGw_CMN6b9zxpS-YgNA3jJc-D15W_XwcCFFQg2GEMobxO5SkPDQGC5i0iM2fhuBLtkatm16B6OfCI/s1600/esProc_prepare_testdata_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWu1maH-9eVI_b8f2emsr-fIopK4HKKeQt-6tUX2g_mwz9KpT0MkDRvr2-BTfunlVGw_CMN6b9zxpS-YgNA3jJc-D15W_XwcCFFQg2GEMobxO5SkPDQGC5i0iM2fhuBLtkatm16B6OfCI/s1600/esProc_prepare_testdata_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">The cities of employees need to be
retrieved randomly from the CITIES table in database: <o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpad69nP1UqrzCg_E-_GRcpXVM35UzDP82FQoHPoFrO9FK94AmCMvS6Nxnb7-ef1HDvDgE794cLblwmqlxCTYzXl8SuP6kNdUSXrcha8fvkStMKEEN2iPS7wnNUa5H_UKvrzntBN2gHPY/s1600/esProc_prepare_testdata_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpad69nP1UqrzCg_E-_GRcpXVM35UzDP82FQoHPoFrO9FK94AmCMvS6Nxnb7-ef1HDvDgE794cLblwmqlxCTYzXl8SuP6kNdUSXrcha8fvkStMKEEN2iPS7wnNUa5H_UKvrzntBN2gHPY/s1600/esProc_prepare_testdata_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">According to the STATEID field in CITIES
table, we can retrieve the abbreviations of the states for the employees from STATES
table</span>:<span lang="EN-US"><o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbXfO4jMZ_iAXTOUxO4yPr3vDQ-zvCSramezbyhYY1GRAfAZP2AcA3KHcDqRBbQCR2gY5Y6Ikc5E27L4xD-btWJJipO4rWhpD9ONijBLHG4DYGZ7915xPczRn3rA7yICu5RqQtvxlK1U/s1600/esProc_prepare_testdata_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbXfO4jMZ_iAXTOUxO4yPr3vDQ-zvCSramezbyhYY1GRAfAZP2AcA3KHcDqRBbQCR2gY5Y6Ikc5E27L4xD-btWJJipO4rWhpD9ONijBLHG4DYGZ7915xPczRn3rA7yICu5RqQtvxlK1U/s1600/esProc_prepare_testdata_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span lang="EN-US"><span style="font-family: inherit;">The code for
preparing test data is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLNhCNsXZbYAQ2n6tJu445nGNULqRiqFzvkgz3WycuOHSeEq3CbLblBRZh7tqnLvDo5PWGNqsIpJzJEp1_6mxiVehGh0wbMb2T1LvumkTXclzSuSEjfpG5XYqTz9XDFC5VPRwzh1Sdvlg/s1600/esProc_prepare_testdata_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLNhCNsXZbYAQ2n6tJu445nGNULqRiqFzvkgz3WycuOHSeEq3CbLblBRZh7tqnLvDo5PWGNqsIpJzJEp1_6mxiVehGh0wbMb2T1LvumkTXclzSuSEjfpG5XYqTz9XDFC5VPRwzh1Sdvlg/s1600/esProc_prepare_testdata_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br />The following is the explanation of the
code in the cellcet.</span><br />
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">The first two lines generate the raw data
of names. Note that when generating the employee information, the name of the
employee is related to his/her gender. Therefore we need to retrieve the text
data first, combine the most used male and female names, and add the gender
field to them: <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">After data is arranged, we can see in C2
the following table sequence consisting of names and genders</span>:<span lang="EN-US"><o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijn-5Fmv5gERCZhO7n48HyXE8fHS8fAc4YOMOOa8qgKYiyKZxXFKHnwM0nnecS3t8ghromDMHEyQRopD3Pk-2ySpKcAUt6ZOEq40MslnEo86YJAlHlCYkvoClQCy_4853FuXzGChLjG4A/s1600/esProc_prepare_testdata_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijn-5Fmv5gERCZhO7n48HyXE8fHS8fAc4YOMOOa8qgKYiyKZxXFKHnwM0nnecS3t8ghromDMHEyQRopD3Pk-2ySpKcAUt6ZOEq40MslnEo86YJAlHlCYkvoClQCy_4853FuXzGChLjG4A/s1600/esProc_prepare_testdata_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Similarly, the cities and the abbreviations
of states are also related. After retrieving data from database in line 3, the
abbreviations of states are added to city information:<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<span lang="EN-US"><span style="font-family: inherit;">After data arrangement, the table sequence of city
information in C3 is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx2nreq7YhTRZ7JDl1EHNXcMSTKmHuw2JpUFdICm7ZROsSMXHPewfniykxD2b8dpX9YnDK1fOxuOT_bBb2K_PMVp8MZvp5qEYAiLF-EqrnyzTiHElFqqYNKFHxZMdvXYvTZmZIjDOyMWs/s1600/esProc_prepare_testdata_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx2nreq7YhTRZ7JDl1EHNXcMSTKmHuw2JpUFdICm7ZROsSMXHPewfniykxD2b8dpX9YnDK1fOxuOT_bBb2K_PMVp8MZvp5qEYAiLF-EqrnyzTiHElFqqYNKFHxZMdvXYvTZmZIjDOyMWs/s1600/esProc_prepare_testdata_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Then the basic information for generating data
is prepared in line 4, including the data structure for employee information
table, and the amount of test data to be generated, etc.:<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">Among this, the number in C4 is the
definition of cache, meaning that after generation of every 1,500 records we
need to output data to the text file. This way we can control the use of memory.
In B5 the data structure of employee information table is output to the text
file. <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;">As the next step, we can now run a loop from
line 6 to line 15 to generate the test data for every employee:<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><span lang="EN-US">B</span><span lang="EN-US">6</span><span lang="EN-US"> <span class="hps">generates
a random sequence number as reference to </span></span><span class="hps"><span lang="EN-US">a
</span></span><span class="hps"><span lang="EN-US">name</span></span><span lang="EN-US">, while C</span><span lang="EN-US">6</span><span lang="EN-US"> <span class="hps">generates</span>
one for </span><span lang="EN-US">a </span><span lang="EN-US">surname.
<span class="hps">They are used to </span></span><span class="hps"><span lang="EN-US">generate</span></span><span lang="EN-US"> <span class="hps">the</span>
<span class="hps">name and gender </span></span><span class="hps"><span lang="EN-US">of an</span></span><span class="hps"><span lang="EN-US">
employee. Accordiing to the requirements, B</span></span><span class="hps"><span lang="EN-US">9</span></span><span lang="EN-US"> <span class="hps">randomly
generates</span> <span class="hps">the age,</span> <span class="hps">and</span> according
to the age, </span><span lang="EN-US">line 10 </span><span class="hps"><span lang="EN-US">select</span></span><span class="hps"><span lang="EN-US">s</span></span><span class="hps"><span lang="EN-US"> a random date in the corresponding</span></span><span lang="EN-US"> <span class="hps">year
as this employee</span>'s birthday. In line <span class="hps">1</span></span><span class="hps"><span lang="EN-US">1</span></span><span class="hps"><span lang="EN-US">, 1</span></span><span class="hps"><span lang="EN-US">2</span></span><span lang="EN-US"> <span class="hps">of the code</span>, <span class="hps">randomly</span>
<span class="hps">select a city</span> and get the city and state for the <span class="hps">employee</span>. <span class="hps">After</span> </span><span class="hps"><span lang="EN-US">the</span></span><span class="hps"><span lang="EN-US"> required
data</span></span><span lang="EN-US">
</span><span class="hps"><span lang="EN-US">is</span></span><span lang="EN-US"> <span class="hps">generated</span>,
B1</span><span lang="EN-US">3</span><span lang="EN-US">
<span class="hps">will add</span> </span><span lang="EN-US">the</span><span lang="EN-US"> data <span class="hps">to the</span>
table </span><span lang="EN-US">sequence </span><span lang="EN-US">of <span class="hps">employee information created in A</span></span><span class="hps"><span lang="EN-US">4</span></span><span class="hps"><span lang="EN-US">.</span></span><span lang="EN-US"> </span><span class="hps"><span lang="EN-US">C14</span></span><span lang="EN-US"> <span class="hps">controls</span> the <span class="hps">data
output,</span> and write data to text file after every <span class="hps">1</span></span><span class="hps"><span lang="EN-US">,</span></span><span class="hps"><span lang="EN-US">500</span></span><span lang="EN-US"> <span class="hps">records</span></span><span class="hps"><span lang="EN-US"> are generated</span></span><span class="hps"><span lang="EN-US">. </span></span><span lang="EN-US">After data output</span><span lang="EN-US">,</span><span lang="EN-US"> A</span><span lang="EN-US">4</span><span lang="EN-US"> is dumped <span class="hps">to avoid too much memory</span></span><span class="hps"><span lang="EN-US">
use</span></span><span lang="EN-US">.
<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: inherit;"><span class="hps"><span lang="EN-US">After</span></span><span lang="EN-US"> <span class="hps">all data</span> <span class="hps">outpu</span></span><span class="hps"><span lang="EN-US">t</span></span><span class="hps"><span lang="EN-US">, the text file </span></span><span class="hps"><span lang="EN-US">is as follows</span></span><span class="hps"><span lang="EN-US">:</span></span><span class="hps"><span lang="EN-US"><o:p></o:p></span></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimI5tmAUEG44I-F7B-CuYAK9sSDBuZNVimHVPJvQMQ4pbP_R3CuI9XuwhjtMffGlk30MusNG7TmN5HZIVNxvOl-q30J_4IWLi6fN_YpcHa5JkJ9EhUxVUwDPLd8T4-HiebomDS5tI1GVw/s1600/esProc_prepare_testdata_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimI5tmAUEG44I-F7B-CuYAK9sSDBuZNVimHVPJvQMQ4pbP_R3CuI9XuwhjtMffGlk30MusNG7TmN5HZIVNxvOl-q30J_4IWLi6fN_YpcHa5JkJ9EhUxVUwDPLd8T4-HiebomDS5tI1GVw/s1600/esProc_prepare_testdata_7.jpg" /></span></a></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span>
<span lang="EN-US"><span style="font-family: inherit;">When preparing test
data with esProc, we can run a loop to generate large amount of random data. Meanwhile,
in the loop, we can invoke existing database data or text data easily, to generate
data according to business needs and to avoid writing complex programs.</span></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-64080763785762652002015-09-06T20:42:00.002-05:002015-09-06T20:42:26.092-05:00esProc Counts Distinct Columns in a Text File <div align="left" class="MsoNormal">
<span lang="EN-US">Problem
source</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">:</span><span lang="EN-US"><a href="http://unix.stackexchange.com/questions/161885/using-awk-to-identify-the-number-identical-columns">http://unix.stackexchange.com/questions/161885/using-awk-to-identify-the-number-identical-columns</a> .<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">There are some text files under /data
directory. Each of them has certain columns. We want to know how many distinct
columns are there in each file. For instance, the number of distinct columns in
f1.txt is 3. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 133.0pt;" valign="top" width="177">
<div class="MsoNormal">
<span lang="EN-US">1 0 0 0 0 0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">0 1 1 1 0 0<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">Suppose there is only one file. Then the
code could be:<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<span lang="EN-US" style="color: #002060;">file(</span><span lang="EN-US" style="color: #002060; font-family: "微软雅黑","sans-serif"; font-size: 9.0pt; mso-bidi-font-family: 微软雅黑; mso-font-kerning: 0pt; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">"</span><span lang="EN-US" style="color: #002060;">/data/f1.txt”).import().fno().((c=#,A3.(~.field(c)))).id().len()<o:p></o:p></span></div>
<div class="MsoNormal">
<i><span lang="EN-US"><br /></span></i></div>
<div class="MsoNormal">
<i><span lang="EN-US">fno</span></i><span lang="EN-US"> function is used to get the number of columns in a two-dimensional
table; ~ represents the loop variable of a loop function; # represents loop
number; and <i>id</i> function is used to
get the distinct columns. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">If there are a great number of files under
/data directory, the code will be more complicated:<o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<span lang="EN-US" style="color: #002060;"><br /></span></div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<span lang="EN-US" style="color: #002060;">pjoin((d=directory@p("/data")),d.((f=file(~).import(),f.fno().((c=#,f.(~.field(c)))).id().count())))<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US">This line of code calculates sequentially the
number of distinct values in each file and joins the results with corresponding
file names. The result table is as follows:<o:p></o:p></span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 267.65pt;" valign="top" width="357">
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184; width: 317px;">
<tbody>
<tr style="height: 13.5pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 127.4pt;" width="170">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">_1<o:p></o:p></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 110.6pt;" width="147">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">_2<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 1;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 127.4pt;" width="170">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">/data/f1.txt<o:p></o:p></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 110.6pt;" width="147">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">3<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 2;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 127.4pt;" width="170">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">/data/f2.txt<o:p></o:p></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 110.6pt;" width="147">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">2<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 3;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 127.4pt;" width="170">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">/data/f3.txt<o:p></o:p></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 110.6pt;" width="147">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">3<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 13.5pt; mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 127.4pt;" width="170">
<div align="left" class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">/data/f4.txt<o:p></o:p></span></div>
</td>
<td nowrap="" style="height: 13.5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 110.6pt;" width="147">
<div align="right" class="MsoNormal" style="mso-pagination: widow-orphan; text-align: right;">
<span lang="EN-US" style="font-family: 宋体; font-size: 11pt;">4<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal">
<span lang="EN-US"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
</div>
<div class="MsoNormal" style="text-indent: 21.0pt;">
<br /></div>
<br />
<div class="MsoNormal">
<span lang="EN-US">For the convenience of observing
computational logic, the above code can be written in multiple cells using a
long statement: <o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFKvU0GCdn-S4fq7sGkMZSAJQ6DSk_eAua5Xzfbyx_x65FUIrNpgcZ43zisgSzMqhubNLQS-1_1swvX0YvKJgvIA-2GiKJBmqP59vHZPC3cEna8-2QgswAF72pAnry7MvQ7G_oI0gZyGY/s1600/2015-09-07_091849.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFKvU0GCdn-S4fq7sGkMZSAJQ6DSk_eAua5Xzfbyx_x65FUIrNpgcZ43zisgSzMqhubNLQS-1_1swvX0YvKJgvIA-2GiKJBmqP59vHZPC3cEna8-2QgswAF72pAnry7MvQ7G_oI0gZyGY/s1600/2015-09-07_091849.jpg" /></a></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US"></span></div>
<div class="MsoNormal">
<span lang="EN-US">== indicates the beginning of the long
statement, whose working range is the indented block of B2-C5. B5 is the last
executable cell whose result will be returned to A2. <o:p></o:p></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-77611907701625738512015-09-06T00:27:00.001-05:002015-09-06T00:28:48.761-05:00esProc Analyzes Upward Trend in Stock Prices<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Here, we use esProc to analyze the upward trend in stock prices. There
is a variety of algorithms, of which one will be illustrated in detail. Other
cases can be handled using the similar codes. Specific requirements are:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Among the stocks which have kept going up for N days, what is the
proportion of those that continue to rise for another day?<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">The key to solve this problem is to compute the maximal days when each
stock kept rising (hereinafter referred to as Rising Days). Divide the number
of stocks where the Rising Days is greater than or equal to <i>n +1</i> by the number of stocks where the
Rising Days is greater than or equal to <i>n</i>
days, this is the rate we evaluate.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Stock data must include three fields: Transaction day, Closing price
and Stock codes. Therefore, the data source may like this:<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">Stock Date Price<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120089 2009-01-01 00:00:00 50.24<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120123 2009-01-01 00:00:00 10.35<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120136 2009-01-01 00:00:00 43.37<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120141 2009-01-01 00:00:00 41.86<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120170 2009-01-01 00:00:00 194.63<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120243 2009-01-01 00:00:00 15.75<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120319 2009-01-01 00:00:00 1.36<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120343 2009-01-01 00:00:00 20.95<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120344 2009-01-01 00:00:00 232.38<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120355 2009-01-01 00:00:00 31.6<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120414 2009-01-01 00:00:00 244.32<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120439 2009-01-01 00:00:00 181.36<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120484 2009-01-01 00:00:00 6.27<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120528 2009-01-01 00:00:00 43.86<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120533 2009-01-01 00:00:00 227.91<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120584 2009-01-01 00:00:00 25.12<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120607 2009-01-01 00:00:00 36.36<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120626 2009-01-01 00:00:00 29.36<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120630 2009-01-01 00:00:00 29.77<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">120642 2009-01-01 00:00:00 30.98<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">…<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-char-indent-count: 2.0; text-indent: 24.0pt;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">The natural way of computing the maximum of Rising Days: Sort closing
prices of each stock are by Transaction dates, and compare each closing price against
the previous one in sequence. If the current closing price is higher than the
previous one, then add 1 to the Rising Days; if not higher, reset the Rising Days
to 0.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">We find that programming idea of esProc is just a natural one.
Therefore, the code written in esProc is more intelligible, and easy to
maintain. Code is shown as follows:<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPNV52FrB5JBLDkEHKgjukBWaXxqdGwgJanf2LfNVPrSl0F5iw5igQzprLGq20riT6J6rMkyOvciZkhT7tqXD4fFxb8oYoA8QHV1I4yBqFUsePVFF9LNg6VZQWAu1TKb2E6yTtfI2hKAk/s1600/2015-09-06_132344.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPNV52FrB5JBLDkEHKgjukBWaXxqdGwgJanf2LfNVPrSl0F5iw5igQzprLGq20riT6J6rMkyOvciZkhT7tqXD4fFxb8oYoA8QHV1I4yBqFUsePVFF9LNg6VZQWAu1TKb2E6yTtfI2hKAk/s1600/2015-09-06_132344.jpg" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit; text-indent: 24pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit; text-indent: 24pt;">Description:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">1.</span><span lang="EN-US" style="text-indent: -14.2pt;">In cell A1, specify
the input value of <i>n</i> as 2 days. If this
is an external call, you can also pass it through the parameter.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">2.</span><span lang="EN-US" style="text-indent: -14.2pt;">In cell A2, import
the source data from txt file. If necessary, you can also retrieve it from the
database or from HDFS.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">3.</span><span lang="EN-US" style="text-indent: -14.2pt;">In cell A3, group
the data by stock IDs. After grouping, each group corresponds to one stock.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">4.</span><span lang="EN-US" style="text-indent: -14.2pt;">Create an empty table
sequence to store the Rising Days for each stock.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">5.</span><span lang="EN-US" style="text-indent: -14.2pt;">In A5, loop
through stock groups one by one, that is, handle one group, or a stock, at a
time. Loop body is from B6 to B10.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">6.</span><span lang="EN-US" style="text-indent: -14.2pt;">In B6, get
stock ID of the first record in the current group; B7 sets an initial value 0
for Rising Days.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">7.</span><span lang="EN-US" style="text-indent: -14.2pt;">B8 sorts data in the
current group by transaction dates.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">8.</span><span lang="EN-US" style="text-indent: -14.2pt;">B9 does loop one
by one within the current group to determine if a closing price is higher than the
previous one. If higher, add 1 to B7; otherwise reset B7 to 0.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">9.</span><span lang="EN-US" style="text-indent: -14.2pt;">B10 appends computed
stock ID and Rising Days to A4, which means the loop ends.</span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span lang="EN-US" style="font-family: inherit; text-indent: -14.2pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: inherit;"><span lang="EN-US" style="text-indent: -14.2pt;">10.</span><span lang="EN-US" style="text-indent: -14.2pt;">In A11, divide the number of stocks in A4 where the
Rising Days is greater than or equal to <i>n
+1</i> by the number of stocks where the Rising Days is greater than or equal
to <i>n</i> days, this is the rate we
evaluate.</span></span></div>
<div class="1" style="margin-left: 65.25pt; mso-char-indent-count: 0; text-indent: 0cm;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: inherit; font-size: 12.0pt; mso-bidi-font-size: 11.0pt;">As we can see, the code that is in line with the natural way of
thinking can diminish the difference between thinking modes of the human brain
and the code’s logic, thus to reduce the difficulty of writing and maintaining
code, improve efficiency and reduce costs.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;">After the programmers are familiar with esProc programming ideas, they
will be able to write more concise codes, as shown below:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0MgkpNczFQiZHRsyjPcrfPoRYJgHk8Gog2v_hYpH6tuJuDbKWjJDj4eZkMRs2rlJ8BZK5t6qzKv2aMRPfn6LAyqPMdUlZ2BqDy5ihDVppWXKqwIZepRaeDl5F8rcpi86JWunb4a7JilY/s1600/2015-09-06_132419.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0MgkpNczFQiZHRsyjPcrfPoRYJgHk8Gog2v_hYpH6tuJuDbKWjJDj4eZkMRs2rlJ8BZK5t6qzKv2aMRPfn6LAyqPMdUlZ2BqDy5ihDVppWXKqwIZepRaeDl5F8rcpi86JWunb4a7JilY/s1600/2015-09-06_132419.jpg" /></span></a></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-7850683453292695032015-09-02T07:30:00.000-05:002015-09-02T07:30:07.189-05:00esProc Simplifies SQL-style Computations–Inter-row Computation<div style="color: #3e3e3e; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
Inter-row computation is one of those complicated SQL-style computations we often need to handle during database application development. For instance, to compute the link relative ratio by dividing each month’s sales amount by that of the last month, or to compute the year-on-year comparison by dividing each month’s sales amount by that of the same month in last year. As some databases don’t provide the window functions of SQL2003-standard (or don’t support them completely), we need to use JOIN operation to realize the inter-row computation. This method produces difficult code and has poor performance. Even if the window functions are used, we will still be faced with problems like the use of nested subquery. The SQL statements in this case are always quite complicated. However, esProc provides an easy and intuitive way to perform the inter-row computation, which will be illustrated through an example.</div>
<div style="color: #3e3e3e; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
<br /></div>
<div style="color: #3e3e3e; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
Table<em> sales</em> stores years of information of orders. Please compute the link relative ratio and the year-on-year comparison of each month in a specified time period based on this table. Some of the original data are as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibF4mXC5g1_ylIdP3DljVK0rRlELgwDmKj8S9HzwTAyVcPDSgPKN6qntkC78HsvDn1igNfcUybS9iFr2i28vHSekAoDKMULa_ahE0WBs6aatofm_3_hVvp9vBCqu4dyA_LwVJfvnOuzYA/s1600/esProc_sql_inter_row_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibF4mXC5g1_ylIdP3DljVK0rRlELgwDmKj8S9HzwTAyVcPDSgPKN6qntkC78HsvDn1igNfcUybS9iFr2i28vHSekAoDKMULa_ahE0WBs6aatofm_3_hVvp9vBCqu4dyA_LwVJfvnOuzYA/s1600/esProc_sql_inter_row_1.jpg" /></a></div>
<br />
esProc code:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGmdebK378iymZ1j1AP6VO1nZ4KMXJzLUw2RT5yPnQk_fdgYADMJqjNiqK5jTh0VTJLLw1wPgXhHY2vKD5yjCA_diXK2PwsB6I8WytLuMhrJT_M0cKnbyY_mLf97OSjcZyqh8yThyphenhyphen2YbY/s1600/esProc_sql_inter_row_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGmdebK378iymZ1j1AP6VO1nZ4KMXJzLUw2RT5yPnQk_fdgYADMJqjNiqK5jTh0VTJLLw1wPgXhHY2vKD5yjCA_diXK2PwsB6I8WytLuMhrJT_M0cKnbyY_mLf97OSjcZyqh8yThyphenhyphen2YbY/s1600/esProc_sql_inter_row_2.jpg" /></a></div>
<br />
A1:Select data from the database according to a specified time period. begin and end are external parameters. For instance, begin=”2011-01-01 00:00:00″, end=”2014-07-08 00:00:00″. Some of the selected data are as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5XNCevEbN6Lq67aI0AEa-Q5kotTiClDZcoSFCJIduiIUIiG7ovJDOsesKiHDgx_GIjMAhSgvUft_5xgxJvPE1n0XFR2KUVOQQzRirheorn308Tj-2WZt43_RdS768KDGRv4Cy_Sx8bAE/s1600/esProc_sql_inter_row_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5XNCevEbN6Lq67aI0AEa-Q5kotTiClDZcoSFCJIduiIUIiG7ovJDOsesKiHDgx_GIjMAhSgvUft_5xgxJvPE1n0XFR2KUVOQQzRirheorn308Tj-2WZt43_RdS768KDGRv4Cy_Sx8bAE/s1600/esProc_sql_inter_row_3.jpg" /></a></div>
<br />
A2<span style="color: blue;">=A1.groups(year(OrderDate):y,month(OrderDate):m; sum(Amount):mAmount)</span><br />
<span style="color: blue;"><br /></span>
This line of code groups the selected data by the year and the month and sums up the sales amount of each month. groups function is used to perform data grouping and summarizing. Its parameters have two parts, the one before the semicolon is a grouping expression, which is <span style="color: blue;">year(OrderDate):y,month(OrderDate):m</span>, and the other one after it is a summarizing expression, which is <span style="color: blue;">sum(Amount):mAmount</span>. The summarized field is named <em>mAmount</em>. Part of the computed result is as follows:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinISrNEISkKL74dvn9OPP9aCy216zC0akLos5FRQb5-uCla4I2Mlbd-zVtOU8kQyoJug7VCM_WvsHwY1TE1jYFxmcqr5vVPy2tN7Vco3G-L7HN_01BG7HCenqaoyH3YIILwYOOOd4kNJg/s1600/esProc_sql_inter_row_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinISrNEISkKL74dvn9OPP9aCy216zC0akLos5FRQb5-uCla4I2Mlbd-zVtOU8kQyoJug7VCM_WvsHwY1TE1jYFxmcqr5vVPy2tN7Vco3G-L7HN_01BG7HCenqaoyH3YIILwYOOOd4kNJg/s1600/esProc_sql_inter_row_4.jpg" /></a></div>
<br />
A3<span style="color: blue;">=A2.derive(mAmount/mAmount[-1]:lrr)</span><br />
<span style="color: blue;"><br /></span>
This line of code adds a new field <em>Irr</em> – the monthly link relative ratio – to the result of A2. The expression for the field is<span style="color: blue;"> mAmount/mAmount[-1]</span>. In esProc, [N] or [-N] is used to refer to Nth record after or before the current one. Thus mAmount in the code represents the sales amount of the current period and mAmount[-1] represents the sales amount of the last period. Result of A3 is as follows:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUojjUOLp-3plLWGbZ8qa75lquyyvYm7oHJXXdIL_Lrt-Q7mCIaHv9-vSbAJxXB-msAe0ToFxCLk2BuRQuL8doFvOuIp0ojTe4ZEu_JGDb8YwDK-N8MUlkJaNZlaUWbqITj_YHc2bCbHA/s1600/esProc_sql_inter_row_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUojjUOLp-3plLWGbZ8qa75lquyyvYm7oHJXXdIL_Lrt-Q7mCIaHv9-vSbAJxXB-msAe0ToFxCLk2BuRQuL8doFvOuIp0ojTe4ZEu_JGDb8YwDK-N8MUlkJaNZlaUWbqITj_YHc2bCbHA/s1600/esProc_sql_inter_row_5.jpg" /></a></div>
<br />
Please note that the link relative ratio of the initial month (January of the year 2011) is empty.<br />
<br />
A4<span style="color: blue;">=A3.sort(m)</span><br />
<span style="color: blue;"><br /></span>
This line of code sorts the data in A3 by the month and the year so as to compute the year-on-year comparison. The complete code is =A3.sort(m,y). Because the data in A3 have been sorted by the year, we just need to sort the data here by the month, that is, A3.sort(m), which gets a higher performance. Part of the result is as follows:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI58XUHea3yQM04HZFKFGu62I2UA52LNFbXTZAL7587hxNTvNdOZnfc9VYYnaDAUabAm7l0KdUSdSSZjqbmEKcj07eAZq3tFC8Q45jaRvuxADEiiWhVISInbIuuVz0PgCUmafrarq2Imw/s1600/esProc_sql_inter_row_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI58XUHea3yQM04HZFKFGu62I2UA52LNFbXTZAL7587hxNTvNdOZnfc9VYYnaDAUabAm7l0KdUSdSSZjqbmEKcj07eAZq3tFC8Q45jaRvuxADEiiWhVISInbIuuVz0PgCUmafrarq2Imw/s1600/esProc_sql_inter_row_6.jpg" /></a></div>
<br />
A5<span style="color: blue;">=A4.derive(if(m==m[-1],mAmount/mAmount[-1],null):yoy)</span><br />
<span style="color: blue;"><br /></span>
This line of code adds a new field yoy – the year-on-year comparison of monthly sale amount – to the result of A4. The expression for the field is <span style="color: blue;">if (m==m[-1],mAmount/mAmount[-1],null)</span>, which means the year-on-year comparison has value only when same months are compared. if function has three parameters, among which <span style="color: blue;">m==m[1-]</span> is a boolean expression. When the value of this expression is true, return <span style="color: blue;">mAmount/mAmount[-1]</span>; when it is false, return <span style="color: blue;">null</span>. Please note that the value of year-on-year comparison of each month of the initial year (the year of 2011) is always null. Part of the result is as follows:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj79kg8bLxr2nWhsHvfOl7IsY6qmv0_vedkV1SCqDkG918THgczH-3a-f9Bopa18f-Cf_efV4xklGEUrQzgRypyH9aDpzwhFZX3-D5wwMimC3z73PQ9Ga_ziOndZWPo1_wRHE1D8prmzKY/s1600/esProc_sql_inter_row_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj79kg8bLxr2nWhsHvfOl7IsY6qmv0_vedkV1SCqDkG918THgczH-3a-f9Bopa18f-Cf_efV4xklGEUrQzgRypyH9aDpzwhFZX3-D5wwMimC3z73PQ9Ga_ziOndZWPo1_wRHE1D8prmzKY/s1600/esProc_sql_inter_row_7.jpg" /></a></div>
<br />
For the convenience of viewing, a line of code – A6=A5.sort(y:-1,m) – can be added, which means sorting the result of A5 by the year in descending order and by the month in ascending order. Please note the data are valid by the end of July of the 2014. Result is as follows:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD-ucqu0HXloImUq9hEdqMP35AHTgZHUd-uFhOpUrhMiwRefBu-B_nrNy8_YFyY68Sda7nkgkhv7VbDcM1Dd4ycy7HxhxIk-0DIWr5-31hRuQY7DNxyAe3FJMZXvoPo1tdFuj3ZQBeRx0/s1600/esProc_sql_inter_row_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD-ucqu0HXloImUq9hEdqMP35AHTgZHUd-uFhOpUrhMiwRefBu-B_nrNy8_YFyY68Sda7nkgkhv7VbDcM1Dd4ycy7HxhxIk-0DIWr5-31hRuQY7DNxyAe3FJMZXvoPo1tdFuj3ZQBeRx0/s1600/esProc_sql_inter_row_8.jpg" /></a></div>
<br /></div>
<div style="color: #3e3e3e; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
<br /></div>
<span style="color: #3e3e3e; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">In addition, an esProc program can be called by the reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to the Java main program. For more details, please refer to the related documents.</span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-68863248491553734132015-09-01T02:05:00.000-05:002015-09-01T02:05:08.952-05:00esProc Simplifies SQL-style computations – Ungrouping<div style="color: #3e3e3e;">
<span style="font-family: inherit;">During database application development, we often need to handle complicated SQL-style computations. One of them is the ungrouping, that is, the opposite process of grouping and summarizing which requires, for example, splitting each record into multiple records. We cannot realize the operation in SQL without taking great trouble. The code is so complicated and difficult to understand.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">By contrast, esProc provides easier way and thus simpler code for realizing the ungrouping. The following are two examples.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In <em>packGather</em>, a table that holds the summarized data of packages of various products, productID field represents the ID numbers of products, packing field represents the number of each product’s packages, all of which have the same number of products, and quantitySum represents the total quantity of a product. Some of the data are as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrq1TqNmyhUFJjRTmUTXqsjMRx8kcs9nsUhwRQMVeaBLWdqe9PDRwLdfgesKPpK9RzwFjYOV_gI_-Q0AhQf3tViIbmItWTKZRGrUF4UmxxW0hNKzU3jfPdb0SN7FWB1Jxko5dMYuqdTyU/s1600/esProc_sql_ungroup_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrq1TqNmyhUFJjRTmUTXqsjMRx8kcs9nsUhwRQMVeaBLWdqe9PDRwLdfgesKPpK9RzwFjYOV_gI_-Q0AhQf3tViIbmItWTKZRGrUF4UmxxW0hNKzU3jfPdb0SN7FWB1Jxko5dMYuqdTyU/s1600/esProc_sql_ungroup_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">We are asked to split packGather into tables of packages, that is, list packages separately and number each of them. Take product b as an example, there are 3 records in the table after it is split.</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQT-ojLVzK_s1WUJ_ZCuKTIpU2YGwyx5WQNXC3hW9m-N0E5PkcJ5yoDHyF5N5Z3TdieFw4Z1XMvE1UBRcpNrS8gwyADdfCV01J34eMTOIByIhITmvKNK3o7VTVLC9wJhHV-zx9eYnWIM/s1600/esProc_sql_ungroup_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQT-ojLVzK_s1WUJ_ZCuKTIpU2YGwyx5WQNXC3hW9m-N0E5PkcJ5yoDHyF5N5Z3TdieFw4Z1XMvE1UBRcpNrS8gwyADdfCV01J34eMTOIByIhITmvKNK3o7VTVLC9wJhHV-zx9eYnWIM/s1600/esProc_sql_ungroup_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">The following esProc code can be used to solve the problem:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbgX4G3ZpPGgLGXf0-QxkDV5HwpK3uW0NcEsw9R7FPOwXUjDvsLysHePQll98GJ48kbqb2G6pbx-GOoWTOGYtogKa2kyLXQnML8Ual1GdJ-INiQlRwhC7RuDl1kcCgC2MqAN8X_ZYJgBk/s1600/esProc_sql_ungroup_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbgX4G3ZpPGgLGXf0-QxkDV5HwpK3uW0NcEsw9R7FPOwXUjDvsLysHePQll98GJ48kbqb2G6pbx-GOoWTOGYtogKa2kyLXQnML8Ual1GdJ-INiQlRwhC7RuDl1kcCgC2MqAN8X_ZYJgBk/s1600/esProc_sql_ungroup_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1:Select all the data from the database. They are as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5t5KjLZFLlPzBy79rxZmlRxg4nNcVB1UbUbvuiHE42M7OZqQ0z0CDge5hQ9yq1r_CA-r6MIY1xLoQbfKriS6gwZNjYL6tkf7BtEmqpfP7pxl2WopyKdyDyYzGblnmw9huSxdx6r93iIo/s1600/esProc_sql_ungroup_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5t5KjLZFLlPzBy79rxZmlRxg4nNcVB1UbUbvuiHE42M7OZqQ0z0CDge5hQ9yq1r_CA-r6MIY1xLoQbfKriS6gwZNjYL6tkf7BtEmqpfP7pxl2WopyKdyDyYzGblnmw9huSxdx6r93iIo/s1600/esProc_sql_ungroup_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A2<span style="color: blue;">= A1.conj(packing.new(~:seq, productID:product, quantitiySum/packing:quan))</span></span></div>
<span style="font-family: inherit;"><span style="color: blue;"><br /></span><span style="color: #3e3e3e;">This line of code first splits each record in A1 into multiple records to create two-dimensional tables. Every two-dimensional table has different number of records but the same structure, with three fields: seq, product and quantity. Then it concatenates these two-dimensional tables to form a general two-dimensional table.</span></span><br />
<span style="color: #3e3e3e; font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The function of conj function is to concatenate data. For example, split the first record in A1. The corresponding code and result are as follows:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /><span style="color: blue;">A1(1).(packing.new( ~:seq,productID:product,quantitiySum/packing:quan))</span></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjalnk2vSqZyfqlCA4OzdPdwMHQfVIbuCdEhDjpKz0L_HKMCKGOPwM0-i2cGFjbB9OICmwK9mzKFMldknjh5EzEM2wTuSlYRJbdx8UeTF1Wxq1_Bk2pWpYth_4FVygaQlIrjJN5WEv5Es/s1600/esProc_sql_ungroup_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjalnk2vSqZyfqlCA4OzdPdwMHQfVIbuCdEhDjpKz0L_HKMCKGOPwM0-i2cGFjbB9OICmwK9mzKFMldknjh5EzEM2wTuSlYRJbdx8UeTF1Wxq1_Bk2pWpYth_4FVygaQlIrjJN5WEv5Es/s1600/esProc_sql_ungroup_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1.conj(…) is equal to [A1(1),A1(2),A1(3)…].conj(…). The final result is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxTUbH7W059bz7o74k9iOd4S8WhOG_ZDaJRwdTxpPyXIEHG39qBU5PFEB0j9LIGyLzCgwXVM5IL67IbUuv_4O60R-H1DpPXinpObFOKlgSvefRskJkAHe0_ntZp4gnQUsTMBHZ8ABf-e4/s1600/esProc_sql_ungroup_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxTUbH7W059bz7o74k9iOd4S8WhOG_ZDaJRwdTxpPyXIEHG39qBU5PFEB0j9LIGyLzCgwXVM5IL67IbUuv_4O60R-H1DpPXinpObFOKlgSvefRskJkAHe0_ntZp4gnQUsTMBHZ8ABf-e4/s1600/esProc_sql_ungroup_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Please note the expression <span style="color: blue;">packing.new(…)</span>, which means creating a new table sequence according to the packing field of each record in A1. <em>new</em> function is used to create a new table sequence based on an existing sequence or table sequence, like<span style="color: blue;"> ["a","b","c"].new()</span> or [<span style="color: blue;">1,2,3…N].new()</span>. The latter can be abbreviated to <span style="color: blue;">N.new()</span>. If, for example, the value of packing field in the first record is 2, this expression will be parsed as <span style="color: blue;">[1,2].new(…)</span>. While creating a new table sequence using <em>new</em> function, we can use “~” to represent members of the original sequence. So ~:<span style="color: blue;">seq</span> in the expression in A2 means using the original sequence as the first field of the new table sequence, with seq being the field name.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A2 represents the final result of this example.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Now let’s look at another example that computes liquidated damages in a database. Here is a table – <em>contract</em> – that has multiple fields, three of which are ID (contract number), enddate (ending date) and amount (contract amount). Please compute how much liquidated damages should be paid each day for each breach of contract, on the assumption that the required liquidated damages per day is one thousandth of the contract amount.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Some of the data of <em>contract</em> are as follows:</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs2y4MGltyuK1VItrxuLza0Kz_wZ65oQMbs4GhV7rX-HBc3FDoUNd_Wcm7dvrIMgM9u4PmXjv42bdt0k_Uixov4KCOJOWiP0r23DjVHjWDFFrT3put-PH7rxssOPUcq2miEnH98zwN1UY/s1600/esProc_sql_ungroup_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs2y4MGltyuK1VItrxuLza0Kz_wZ65oQMbs4GhV7rX-HBc3FDoUNd_Wcm7dvrIMgM9u4PmXjv42bdt0k_Uixov4KCOJOWiP0r23DjVHjWDFFrT3put-PH7rxssOPUcq2miEnH98zwN1UY/s1600/esProc_sql_ungroup_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">esProc code:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjija9cc9bPuwUzjz6uS8CI8H_mCkJCZwPPECyo5e3Cjrc9C0UpbraqYy9MxlTKEWH-B8BqW7a_4Rs9m7LhrCtx51C4ShAJcbW9tI6Lw5HfDu2UDJygSFdUV-7uf8nZKggy76Rp7yrQTqE/s1600/esProc_sql_ungroup_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjija9cc9bPuwUzjz6uS8CI8H_mCkJCZwPPECyo5e3Cjrc9C0UpbraqYy9MxlTKEWH-B8BqW7a_4Rs9m7LhrCtx51C4ShAJcbW9tI6Lw5HfDu2UDJygSFdUV-7uf8nZKggy76Rp7yrQTqE/s1600/esProc_sql_ungroup_8.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">This piece of code uses periods function to generate a sequence of dates starting from the ending date of a contract to the current date. # represents the current sequence number in the time sequence. The final result is as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghW8bYeD2keRJMulDw-Bii1uZhVNoQFxsha0UqzZYKlRi_b5XEv8GYjPTBFEGzFg1CTqYt1OdxlQ5z21Btfw2xpJQJ_-1DamyzqggwA-C7tA3m2ryPglomBz2vVKRiPpyFFjqcwjAgE6k/s1600/esProc_sql_ungroup_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghW8bYeD2keRJMulDw-Bii1uZhVNoQFxsha0UqzZYKlRi_b5XEv8GYjPTBFEGzFg1CTqYt1OdxlQ5z21Btfw2xpJQJ_-1DamyzqggwA-C7tA3m2ryPglomBz2vVKRiPpyFFjqcwjAgE6k/s1600/esProc_sql_ungroup_9.jpg" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Note: esProc program can be called by a reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a result of the form of ResultSet to the Java main program. Please refer to the related documents for details.</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-43319718596372250272015-08-31T02:43:00.000-05:002015-08-31T02:43:03.620-05:00esProc Simplifies SQL-style Computations – Data Sorting by Specified Order<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Data sorting by a specified order is one of the complicated SQL-style computations we often need to deal with during the database application development. The computation requires that data be sorted by a specified order rather than in ascending or descending order. For example, sort data according to the order of <span style="color: blue;">2,3,1</span>, or of <span style="color: blue;">“DSGC”,”TAS”,”GC”,”HU”</span>. If a table can be created to store the criteria in the database, we can sort data using JOIN statement. But in many cases the sorting criteria are dynamic, or in the database a table is not allowed to be created, thus we should perform UNION before JOIN, or use <em>decode</em> function. We can do so when the sorting criteria are short. Sometimes they are quite long, and we must write long UNION and <em>decode</em> strings manually, which causes mistakes frequently.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">esProc, however, can perform this kind of computation easily. Let’s look at how it works through an example.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">There is a table – LIQUORS – that holds inventory of a great many liquors. Now the records need to be sorted according to a specified LID order, like “2, 1 , 3, 4, 5…”. Some of the data in table LIQUORS are as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIe8ZkggrWko27vl_HEZTkZnhtDeBTJseAPu62IOfc0unFqBi1H7bF8QcbilBtA-LrzKcKla6nKndbIdGWl4X1rayZtKHLGVJs-_VwSMm8oLb4dpAKLFk4AprNdnunUHY_Y8FAqv5apxY/s1600/esProc_sql_sort_order_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIe8ZkggrWko27vl_HEZTkZnhtDeBTJseAPu62IOfc0unFqBi1H7bF8QcbilBtA-LrzKcKla6nKndbIdGWl4X1rayZtKHLGVJs-_VwSMm8oLb4dpAKLFk4AprNdnunUHY_Y8FAqv5apxY/s1600/esProc_sql_sort_order_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">esProc code:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaY0ODXOP89EUU2bHZTfqwnTK0U75Xm1-f3AaW-vDY4bkjl1N_zv8dtjOS1Zm1qlttWc42DK0T5UjvVXCSLZres8bcG1FYdbx_jXA_yL2oapiM95lNI73gnTDk31ewAmqI24Sm02Hgjxo/s1600/esProc_sql_sort_order_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaY0ODXOP89EUU2bHZTfqwnTK0U75Xm1-f3AaW-vDY4bkjl1N_zv8dtjOS1Zm1qlttWc42DK0T5UjvVXCSLZres8bcG1FYdbx_jXA_yL2oapiM95lNI73gnTDk31ewAmqI24Sm02Hgjxo/s1600/esProc_sql_sort_order_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1:Select all the data from LIQUORS. Some of the data are as follows: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnQeVQKJJ8IFX5KE1xuLyjex266VGIyQ_lody_MQQw9QYmkTTMTDJdid8D4wASsJ8tizwNUwfVeQK60NogDKymuYe6eSAeF2abUmZgSkvQSldKOHmd6MpBCQHeSTdopg2FMcAudikX7lA/s1600/esProc_sql_sort_order_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnQeVQKJJ8IFX5KE1xuLyjex266VGIyQ_lody_MQQw9QYmkTTMTDJdid8D4wASsJ8tizwNUwfVeQK60NogDKymuYe6eSAeF2abUmZgSkvQSldKOHmd6MpBCQHeSTdopg2FMcAudikX7lA/s1600/esProc_sql_sort_order_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A2=A1.align@s([2,1,3,4,5], LID). This line of code sorts LID field in the object of A1 according to the order of 2, 1, 3, 4, 5. The result is as follows: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwqgqeucEB__u6Ipwuqul4-HKFUspo_0tAiGSaOSzEiM-AlZMIAOQLGUVoF4bcCyxGBkl_Cjf71yHSthNHUYJPCoQWKRzDpig319afTzsOwmE6f603BtabBA1aH8xuVdZmwH8bkP0aVGY/s1600/esProc_sql_sort_order_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwqgqeucEB__u6Ipwuqul4-HKFUspo_0tAiGSaOSzEiM-AlZMIAOQLGUVoF4bcCyxGBkl_Cjf71yHSthNHUYJPCoQWKRzDpig319afTzsOwmE6f603BtabBA1aH8xuVdZmwH8bkP0aVGY/s1600/esProc_sql_sort_order_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">The sorting criterion can also be an external parameter. For example, define a parameter – arg1, modify the code in A2 into =A1.align(arg1, LID), execute the script (which can be called by a Java program or a reporting tool as well) and enter [2,1,3,4,5] in the Input argument window, as shown below:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlQuFyOE-aRCGeZxvAmnuVTV1WGpoDH_HQkkTafY6G8cFPUT8Ut6qy9rFRLZLEEa94AtTcFLztGQuAXJqiOF946Mtjs7BhTTM7gBxpqiDJ-ZcOkbfsjQmJ_3yV1795EFqRBfLG07LQLiA/s1600/esProc_sql_sort_order_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlQuFyOE-aRCGeZxvAmnuVTV1WGpoDH_HQkkTafY6G8cFPUT8Ut6qy9rFRLZLEEa94AtTcFLztGQuAXJqiOF946Mtjs7BhTTM7gBxpqiDJ-ZcOkbfsjQmJ_3yV1795EFqRBfLG07LQLiA/s1600/esProc_sql_sort_order_5.jpg" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The computed result is completely the same as that got by executing the previous code:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In addition to solving problems of data sorting by a specified order, esProc can provide good solution to problems of data grouping with fixed criteria. As to more information in this respect, please refer to <a href="http://blog.raqsoft.com/?p=1496" style="text-decoration: none;">esProc Simplifies SQL-style computations – Data Grouping with Fixed Criteria</a>.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">esProc program can be called by a reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a result of the form of <em>ResultSet</em> to the Java main program. For more details, please refer to the related documents.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-76744119892240111172015-08-28T01:15:00.000-05:002015-08-28T01:16:54.247-05:00esProc Simplifies SQL-style Computations – Transpose Rows and Columns<div style="color: #3e3e3e;">
<span style="font-family: inherit;">During database application development, we often need to deal with complicated SQL-style computations. The transposition of rows and columns is one of them. Oracle uses <strong>pivot</strong> function to realize this computation. The other databases haven’t the counterparts to realize it directly, which makes the corresponding code difficult to write, understand and maintain. Besides, even the <strong>pivot</strong> function can only transpose the fixed columns, but is powerless about the unfixed ones. So are the other databases. Generally all of them must resort to the high level programming languages to realize the dynamic SQL.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">However, coding this computation with esProc will be concise and easy to understand. We’ll use an an example to illustrate this.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The following figure shows part of the SALES – a database table where order data are stored.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGPnE1nBi8lgmCrsLv_hYt7m7QnWuCuKbotvm0b-bqUfIPU-LbVDGVvRB61D4uDRkh-oG7DaxiqbHIRsig8BBOgrmAsYXLs52xPhsQb2AN4VMcIbvpxnW6pDNPpDhOEjwaTh8V9ZW7Zcw/s1600/esProc_sql_transpose_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGPnE1nBi8lgmCrsLv_hYt7m7QnWuCuKbotvm0b-bqUfIPU-LbVDGVvRB61D4uDRkh-oG7DaxiqbHIRsig8BBOgrmAsYXLs52xPhsQb2AN4VMcIbvpxnW6pDNPpDhOEjwaTh8V9ZW7Zcw/s1600/esProc_sql_transpose_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">It is required to compute the total order amount, the maximum and minimum order amount, and the total number of orders of each month of the year 2013, and then transpose the data into a table with thirteen columns and four rows, in which the four operations occupy the first column, with subtotal being the column name, and every month covers a column, with the column names being 1, 2, 3, 4… The first five fields are as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcCM0yKJjz_q6o9zBmlh5_R5H31cJz15Wp2EtqPO1xU4w1nd5zvd75fjjPfWWFbyXMP6gtzXwCpLa11fXDF0XH6x4cbA-kAqC1NljgAOzdGSS9MRnKZ9Z3mpkEIvTHHplx3x3N_fvBZ1I/s1600/esProc_sql_transpose_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcCM0yKJjz_q6o9zBmlh5_R5H31cJz15Wp2EtqPO1xU4w1nd5zvd75fjjPfWWFbyXMP6gtzXwCpLa11fXDF0XH6x4cbA-kAqC1NljgAOzdGSS9MRnKZ9Z3mpkEIvTHHplx3x3N_fvBZ1I/s1600/esProc_sql_transpose_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">esProc code:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvOLkTKUnJbCDL-xwhWmX_M4Pk_j5fVEwoYcbR9wMkVU5b2BTp_uwAwZYSIkt037Zy6iu31piWAbapdOEu4XQvqW_EHVhWaPZVvBXNrEBUBqpURAGc-e4w910xM0d10ZYu7e6N_eTxAyE/s1600/esProc_sql_transpose_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvOLkTKUnJbCDL-xwhWmX_M4Pk_j5fVEwoYcbR9wMkVU5b2BTp_uwAwZYSIkt037Zy6iu31piWAbapdOEu4XQvqW_EHVhWaPZVvBXNrEBUBqpURAGc-e4w910xM0d10ZYu7e6N_eTxAyE/s1600/esProc_sql_transpose_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">A1:Execute the SQL statement of selecting the data of the year 2013 and grouping and summarizing the data by the month. Result is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSLyk9ZhTY1A7jkDmKphcXNRh6vI3AQ61u-bL2UnpDzgLVsKulfDzjI4jFzokDny5ReSmqZUHNtW51BPVxa3rI3YBuFNW2dp_7cEhOrZueOqz56-CMq1xqgr0jJQ37aXGSSOra4GsLD8M/s1600/esProc_sql_transpose_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSLyk9ZhTY1A7jkDmKphcXNRh6vI3AQ61u-bL2UnpDzgLVsKulfDzjI4jFzokDny5ReSmqZUHNtW51BPVxa3rI3YBuFNW2dp_7cEhOrZueOqz56-CMq1xqgr0jJQ37aXGSSOra4GsLD8M/s1600/esProc_sql_transpose_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This simple SQL statement for data grouping and summarizing is supported by any database. The difficulty is the transposition of rows and columns following it.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;">A2=create(subtotal).record(["OSum","OMAX","OMIN","OCount"])</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code creates an empty table sequence where there is only one field: subtotal, as shown below:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsZcCOgfWu6DjjmqLBmm7n8cE85mn10_XfCxTGFguEaSzCTQQrEe8m_8LjHQNRZAd9IEXHD1WJ5ygOPrureK87fxu6p1ysi0q5D51RwUVrVpOXK1jPqFk8RO3XuOMXxFD4CsOPVfzOnSw/s1600/esProc_sql_transpose_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsZcCOgfWu6DjjmqLBmm7n8cE85mn10_XfCxTGFguEaSzCTQQrEe8m_8LjHQNRZAd9IEXHD1WJ5ygOPrureK87fxu6p1ysi0q5D51RwUVrVpOXK1jPqFk8RO3XuOMXxFD4CsOPVfzOnSw/s1600/esProc_sql_transpose_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Note: A table sequence is a data type in esProc. It is a structured two-dimension table similar to the data table of in SQL, but with more powerful function and more flexible usage. By the way, the result of A1 is a table sequence as well.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;">B2=A2.derive(${to(A1.len()).string()}).</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code adds twelve columns to the table sequence in A2 and thus forms the data structure after the transposition, as shown below:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvtTS0rutbN_k8nkOk-gHyG2V072LUkfKKXsO-VDw2-90Omjmtjwf-T8YpiWw6xXSskW48We0N8jYKH61Ui1JuRNoJatf9ZnPjvacgR5_K_nomt0Z1lKJs3czIk7RD-vyW4OhjXlFEmKc/s1600/esProc_sql_transpose_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvtTS0rutbN_k8nkOk-gHyG2V072LUkfKKXsO-VDw2-90Omjmtjwf-T8YpiWw6xXSskW48We0N8jYKH61Ui1JuRNoJatf9ZnPjvacgR5_K_nomt0Z1lKJs3czIk7RD-vyW4OhjXlFEmKc/s1600/esProc_sql_transpose_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">derive function is used to add new columns to an existing table sequence so as to form a new one. For example, <span style="color: blue;">derive(1)</span> means adding one column, where 1 is the field name and the field value is the same as the column name. <span style="color: blue;">derive(0:field1, null:field2)</span> means adding two columns, where, respectively, field names are field1 and field2 and field values are 0 and null.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">According to the requirement of transposition, twelve columns should be added here, for which the code should be <span style="color: blue;">derive(1,2,3,4,5,6,7,8,9,10,11,12)</span>. A macro, that is <span style="color: blue;">${}</span>, whose role is to convert a string into an expression, is used here in order to generate the code dynamically.<span style="color: blue;"> to(A1.len())</span> in the macro is a sequence, whose value is [1,2,3,4,5,6,7,8,9,10,11,12]. The function <strong>string()</strong> is used to convert the sequence into the string “1,2,3,4,5,6,7,8,9,10,11,12”.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A3-A5:Perform loop on A1, accessing one record each time, rearranging it vertically and, at the same time, modifying the corresponding column in the table sequence in B2. Please note the working range of the loop statement can be represented by the indentation, with no need of using braces ({}), or begin/end. So both B4 and B5 are in the working range and neither A4 nor A5 is in it.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Note: In esProc’s loop body, the loop variable is the cell where for statement is entered. In other word, A3 can be used to reference the current record and A3.MONTH can be used to reference the MONTH field of the current record.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;">B4=A3.OSum | A3.OMAX | A3.OMIN | A3.OCount</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code concatenates the summarized fields of the current record in columns. The operator “|” represents concatenation. For example, the records of December in A1 should be like this after being concatenated:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXlc0hFM4SHV0PhZzBGo5TEbgpljbxbUy0iXn2_MEH35nw8IMp9iBP0AzhXCiAeg1zbAuIbcwCZb07pC6V9IWSwuqg61YhP9l4HaMcOWvTTo9aWB1RRV8J-bLc44rSUj5ckkVeF9JV3Uo/s1600/esProc_sql_transpose_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXlc0hFM4SHV0PhZzBGo5TEbgpljbxbUy0iXn2_MEH35nw8IMp9iBP0AzhXCiAeg1zbAuIbcwCZb07pC6V9IWSwuqg61YhP9l4HaMcOWvTTo9aWB1RRV8J-bLc44rSUj5ckkVeF9JV3Uo/s1600/esProc_sql_transpose_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A3.OSum in the code represents the OSum field of the current record. Since OSum is the second field of the records, it can be referenced by its sequence number, thus the code shall be written as A3.#2. </span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Equally, the above line of code can be put as <span style="color: blue;">B4=A3.#2 | A3.#3 | A3.#4 | A3.#5.</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;">B5=eval(“B2.run(B4(#):#”+ string(#A3+1)+ “)”).</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code means modifying the fields in B2 based on the result of B4.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">eval function parses strings into expressions dynamically. For example, the computed result of <span style="color: blue;">eval(“2+3″)</span> is 5; and here <span style="color: blue;">B2.run(B4(#): #13)</span>, the loop code for December, in eval function means inserting members of B4 in order into the 13th column (i.e. December) in B2 according to the sequence numbers of the records in B2.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">run function is used to modify the fields. For instance, <span style="color: blue;">run(field1+field2:field1, 0:#2)</span> means modifying the value of field1 into field1+field2 and the value of the second field (i.e. #2) into 0.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><span style="color: blue;">#A3</span> means the current loop number. Its value is 1 when the first loop is being executed, and the value is 2 when the second one is being executed, and so on and so forth.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">When the loop statement in A3-B5 is executed, the final result will be got in B2. The first several columns are as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLYmEjPZ1EOr4QSEMqvmoUjfiXg7rYSHM8o4qjpFPLC2YF-1YukxENraBQDDnxljbvcYSlzq_LyN6suGxhN-jX5JCgj2UAY7QN56c619jaeIdxly-8WgBJJAhzAOjeUrmvcMVn9zk7Mc0/s1600/esProc_sql_transpose_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLYmEjPZ1EOr4QSEMqvmoUjfiXg7rYSHM8o4qjpFPLC2YF-1YukxENraBQDDnxljbvcYSlzq_LyN6suGxhN-jX5JCgj2UAY7QN56c619jaeIdxly-8WgBJJAhzAOjeUrmvcMVn9zk7Mc0/s1600/esProc_sql_transpose_8.jpg" /></span></a></div>
<span style="color: #3e3e3e; font-family: inherit;">In addition, esProc program can be called by the reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to the Java main program. For more details, please refer to the related documents。</span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-66882805041299797002015-08-27T02:35:00.000-05:002015-08-27T02:35:09.447-05:00esProc Simplifies SQL-style Computations– Get Top N Rows of Each Group<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The operation of getting the top N rows of data is common, such as the biggest salary raise of each employee, the three lowest scores in playing golf and the five days of each month when each product has its biggest sales. SQL resorts to advanced techniques, like window functions and keep/top/row number, to solve this kind of problem. Therefore the code is quite difficult. And as many databases (like MYSQL) doesn’t support these advanced techniques, they can only realize this operation using complicated JOIN statement and nested subquery. If multi-layered groups or multi-level relationships are involved, the computation will become even more complicated.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Yet esProc’s <em>top</em> function can select the top N rows of data of each group according to the row numbers as well as the maximum and minimum values, thus the computation will be made simpler. The following example will teach you how esProc works. <em> </em></span></div>
<div style="color: #3e3e3e;">
<em><span style="font-family: inherit;"><br /></span></em></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><em>golf</em>, a database table, stores scores members have got in playing golf. Please select the three highest scores each member has had. Some of the data are as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiN6OlVz-qIqA3gWRzdXrXiTcH7hZyT3BwWNIiX_cwy37O_dI3df7vyWKt6Uox-J-UFX7f8durKRgyLC3yNmV-lBxr6LLNlxteENLR9CS7QyAIJQQ47PARQyDdh35wCwmnf_YhqK4trBHc/s1600/esProc_sql_topn_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiN6OlVz-qIqA3gWRzdXrXiTcH7hZyT3BwWNIiX_cwy37O_dI3df7vyWKt6Uox-J-UFX7f8durKRgyLC3yNmV-lBxr6LLNlxteENLR9CS7QyAIJQQ47PARQyDdh35wCwmnf_YhqK4trBHc/s1600/esProc_sql_topn_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">esProc Code:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1-p0iZaUOkxANAmajrObSVsBm8vU_eNGKtW5CPNgfqxm5OYTa8fHWucS-wmNIGxxoM3v_jTRfsZVZdmmAUzukpFiL-K1BFCKKky_tJdGbzo-WrXxQj2sTgIkPYIR9fYzzRrlQvR4esWU/s1600/esProc_sql_topn_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1-p0iZaUOkxANAmajrObSVsBm8vU_eNGKtW5CPNgfqxm5OYTa8fHWucS-wmNIGxxoM3v_jTRfsZVZdmmAUzukpFiL-K1BFCKKky_tJdGbzo-WrXxQj2sTgIkPYIR9fYzzRrlQvR4esWU/s1600/esProc_sql_topn_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1:Select data from the database. Click the cell and you can see the result in detail:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuvCsSALB6ngVlXgSaAmkQVKH-8ud_udMICJTIL_X-0DZJozDFNioA9dMY35a0kqMXQpZCib0sTnsZqfLb3bcYMBO0434hIKLQ-U1I4AuChoMX4k7tb36-HVInmoQwQAxQl5oZCKJ9RJ8/s1600/esProc_sql_topn_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuvCsSALB6ngVlXgSaAmkQVKH-8ud_udMICJTIL_X-0DZJozDFNioA9dMY35a0kqMXQpZCib0sTnsZqfLb3bcYMBO0434hIKLQ-U1I4AuChoMX4k7tb36-HVInmoQwQAxQl5oZCKJ9RJ8/s1600/esProc_sql_topn_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A2:=A1.group(User_ID). The code groups the selected data in A1. Result is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtLxxR9A0XMV7XhQQyZiONHbGd_xoy_XivUL_lDIfykZapXimjRLJlS3qAU9Tjs6OUFV-HAL7qkmKfa9VKkNzidDk5Ow39_7Om_tw4fNdpbfZst56T2VZVGDJe4e3SRdk8kruJPzzudtA/s1600/esProc_sql_topn_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtLxxR9A0XMV7XhQQyZiONHbGd_xoy_XivUL_lDIfykZapXimjRLJlS3qAU9Tjs6OUFV-HAL7qkmKfa9VKkNzidDk5Ow39_7Om_tw4fNdpbfZst56T2VZVGDJe4e3SRdk8kruJPzzudtA/s1600/esProc_sql_topn_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">As shown in the above figure, the selected data have been divided into multiple groups by User_ID, with each row representing a group. Click the hyperlinks in blue and you can see members of each group: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinkzhIu3PowXX3LlsRzbV9Y14VKAURmetWrUrAj3v_iWR4wUQwUeuA_-z6B0F7E4JLVIf0CkMNKJvvXNK1IR7xqXsgzVeUT06SLq-WjF43ee8SoztqGtTP787fJ3Mu4JFwGMI1thgbD8M/s1600/esProc_sql_topn_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinkzhIu3PowXX3LlsRzbV9Y14VKAURmetWrUrAj3v_iWR4wUQwUeuA_-z6B0F7E4JLVIf0CkMNKJvvXNK1IR7xqXsgzVeUT06SLq-WjF43ee8SoztqGtTP787fJ3Mu4JFwGMI1thgbD8M/s1600/esProc_sql_topn_5.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A3:=A2.(~.top(-Score;3)). The code gets the top three records of Score field of each group. Here “~” represents each group of data and ~.top() represents that top function is used to compute each group of data in order. top function can get the top N records of a data set. For example, top(Score;3) means sorting the records in ascending order by Score field and getting the top 3 records (i.e. the three smallest values); top(-Scroe;3) means sorting the records in descending order by Score field and getting the top 3 records (i.e. the three biggest values); and top(#;3) means getting the top three records according to the original order. The computed result of this step is as follows: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx1XOjK3kJJQaKaUyCQzAQGt1_2xKRVSrQyRLVhSn7e_BjMjTobty_tQM1f5kvLuM1rMnIa6rxvcTzfSa9wqjwsQFm3kyS-aZDqVIU5srt3c8MPJoxIC_Tqm1ydXgxBGMndUoeZ9eBAAE/s1600/esProc_sql_topn_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx1XOjK3kJJQaKaUyCQzAQGt1_2xKRVSrQyRLVhSn7e_BjMjTobty_tQM1f5kvLuM1rMnIa6rxvcTzfSa9wqjwsQFm3kyS-aZDqVIU5srt3c8MPJoxIC_Tqm1ydXgxBGMndUoeZ9eBAAE/s1600/esProc_sql_topn_6.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A4:=A3.union(). It performs union operation on each group of data. Result is as follows: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCHqF3ovroAlhyJs9OCQ8gh5Rmdw5LmoGHiwiyOy4a195iajafeajKxkjaCRE2QyFzmWCViIVE41YLfXWrLi8yMb1hLtg03ANPQ7v1tYyi2sW-n42CUs5maytTytEn8RQA8jTT5OGpJQo/s1600/esProc_sql_topn_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCHqF3ovroAlhyJs9OCQ8gh5Rmdw5LmoGHiwiyOy4a195iajafeajKxkjaCRE2QyFzmWCViIVE41YLfXWrLi8yMb1hLtg03ANPQ7v1tYyi2sW-n42CUs5maytTytEn8RQA8jTT5OGpJQo/s320/esProc_sql_topn_7.jpg" width="320" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The above four steps can also be combined into one step for the convenience of maintenance and debugging. Thus the code will be <span style="color: blue;">db.query(“select * from golf”).group(User_ID). (~.top(-Score;3)).union()</span>.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In addition, esProc program can be called by the reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result in the form of ResultSet to the Java main program. Please refer to related documents for more details.</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-68558128654145408942015-08-26T01:16:00.000-05:002015-08-26T01:19:14.554-05:00esProc Simplifies SQL-style Computations – Data Grouping with Fixed Criteria<div style="color: #3e3e3e;">
<span style="font-family: inherit;">During database application development, we often need to handle complicated SQL-style computations. Data grouping with fixed criteria is just one type of these. It refers to the computation whose grouping criteria not come from the to-be-grouped data, but from the outside, such as another table, the external parameters or a list of conditions. For the operation of data grouping with fixed criteria in certain cases, like the one in which the grouping criteria are defined by another table and no specific grouping order is required, it can be realized easily in SQL. But for the other cases, SQL has difficulty in realizing the operation. esProc, however, provides easy solutions to various problems of this operation, which will be illustrated through the following examples.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A table – <em>sales </em>- stores the records of orders, in which column CLIENT contains names of clients and column AMOUNT contains order amounts. Now group the table according to the “list of potential clients” and sum up column AMOUNT of each group. Some of the data of <em>sales</em> are displayed in the following figure:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh95k_6B556KrPjBP9r447rzRx7Q2B8QpZGdIISjFuiAwi4OPA9L9LDRisu-Y7iAfOFY0WJ8DmlGHvkvwrmTbWWf2BRk5QjHAZJQEiC4UPsE8uK63OmIRl-xRq4OBje1RCBlYe82cZj45g/s1600/esProc_sql_fixedcriteria_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh95k_6B556KrPjBP9r447rzRx7Q2B8QpZGdIISjFuiAwi4OPA9L9LDRisu-Y7iAfOFY0WJ8DmlGHvkvwrmTbWWf2BRk5QjHAZJQEiC4UPsE8uK63OmIRl-xRq4OBje1RCBlYe82cZj45g/s1600/esProc_sql_fixedcriteria_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Example 1</strong>:The “list of potential clients” comes from the Std field of another table -<em> potential</em> – and only has four records, which are TAS, DSGC, GC and ZTOZ in order. Client ZTOZ is not in <em>sales</em>. It is required to group and summarize the data according to these four records in their order.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">If no specific order is required, this operation can be realized easily with SQL. The corresponding code is as follows:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span>
<span style="color: blue; font-family: inherit;">select potential.std as client, sum(sales.amount) as amount from potential left join client on potential.std=sales.client group by potential.std.</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue; font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">But since a specific order is required in this example, a field for sorting the data must be added if SQL is used to realize the operation and this field should finally be removed using subquery . By contrast, it will be much easier to perform the operation in esProc, as the following code shows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAaVJxYwDKNjp_JgkYCeucPhyzZwkiM6a05JnDbblhVsPf6bXF1ghJwyrF17kgnEGNy56i_jjsFy25jvD0qVmI8hZ8wgTRwT3xGl_NjgQfVqNtbxvELHhyzKrOUFtx3JHs3zE7iRRhKAU/s1600/esProc_sql_fixedcriteria_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAaVJxYwDKNjp_JgkYCeucPhyzZwkiM6a05JnDbblhVsPf6bXF1ghJwyrF17kgnEGNy56i_jjsFy25jvD0qVmI8hZ8wgTRwT3xGl_NjgQfVqNtbxvELHhyzKrOUFtx3JHs3zE7iRRhKAU/s1600/esProc_sql_fixedcriteria_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">A1,B1:Query data from the database, and name the two groups of selected data respectively as sales and potential, as shown below:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgScMjz9yQx-9m2z_T8uOixw_h8RLJ3NVxp9PzMaFPMfS8orsJhv5PSSnYV-IB56_khVejWWE-H-4WImfKLs_nsURuOOfHKbxzOgAedJaW7DD-XePzaU36v9WsN2lPsGCnYA8aP3Dwahm4/s1600/esProc_sql_fixedcriteria_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgScMjz9yQx-9m2z_T8uOixw_h8RLJ3NVxp9PzMaFPMfS8orsJhv5PSSnYV-IB56_khVejWWE-H-4WImfKLs_nsURuOOfHKbxzOgAedJaW7DD-XePzaU36v9WsN2lPsGCnYA8aP3Dwahm4/s1600/esProc_sql_fixedcriteria_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">A3:=sales.align@a(potential:Std,Client) This line of code uses align function to divide the Client field of sales into four groups according to the Std field of potential, as shown in the following figure:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUlqgezpVU4RpgVpkVdfT59fcc0yEjjfFgDmQo6Zv_eUtkbmA38ojhTtylMJIlWX_4PUSrmjcQIT0h4HVb6tz2DggRa5AB-mCc4d1ygCC_P5BxYfwlTCQ-BqwmN3YeDasQ_0MVlfdrOxs/s1600/esProc_sql_fixedcriteria_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUlqgezpVU4RpgVpkVdfT59fcc0yEjjfFgDmQo6Zv_eUtkbmA38ojhTtylMJIlWX_4PUSrmjcQIT0h4HVb6tz2DggRa5AB-mCc4d1ygCC_P5BxYfwlTCQ-BqwmN3YeDasQ_0MVlfdrOxs/s1600/esProc_sql_fixedcriteria_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">It can be seen that the data of the first three groups have existed in <em>sales</em>, while those in the fourth group are not included in it. So the value of the fourth group is empty. The <em>@a</em> option of align function means fetching all the eligible data of each group; without it only the first eligible data of each group will be fetched.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A4:<span style="color: blue;">=pjoin(potential.(Std),A3.(~.sum(Amount)))</span></span></div>
<div>
<span style="font-family: inherit;"><span style="color: blue;"><br /></span><span style="color: #3e3e3e;">This line of code joins two groups of data using</span><em style="color: #3e3e3e;"> pjoin</em><span style="color: #3e3e3e;"> function. One part is </span><span style="color: blue;">potential.(Std)</span><span style="color: #3e3e3e;">, which represents the </span><em style="color: #3e3e3e;">Std</em><span style="color: #3e3e3e;"> field of </span><em style="color: #3e3e3e;">potential</em><span style="color: #3e3e3e;">, and the other part is </span><span style="color: blue;">A3.(~.sum(Amount))</span><span style="color: #3e3e3e;">, which means summing up the</span><em style="color: #3e3e3e;"> Amount</em><span style="color: #3e3e3e;"> field of each group in A3. The final result of this example is as follows:</span></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0OXQmr0SbXWXug9fdTuB8-bUwsolaHuU-atbHnvDmme4KPg6-W-BtwY8fAKo5Gqmn97eYIn9snI7jyT-v2zmEJLQjC8J4hdjU5EqlQtnZL1blKAYS2warR_IulLPhPpI4C-yf5U4nVOg/s1600/esProc_sql_fixedcriteria_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0OXQmr0SbXWXug9fdTuB8-bUwsolaHuU-atbHnvDmme4KPg6-W-BtwY8fAKo5Gqmn97eYIn9snI7jyT-v2zmEJLQjC8J4hdjU5EqlQtnZL1blKAYS2warR_IulLPhPpI4C-yf5U4nVOg/s1600/esProc_sql_fixedcriteria_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">Example 2:The list of potential clients has fixed values but there are many clients in it many. If there are only a small number of clients, union statement can be used in SQL to combine all the clients into a pseudo table. But the method is not desirable if there are a large number of clients, and a new table must be created to store the data permanently. Yet the use of esProc can save us the trouble of creating the table. The esProc code is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGzddXsNspRiPunGYA_1V5IR6vV-BE9bby8BwaLS8KHK0ipyEon-VJzf2fF0pMxVPPj6LzF5Uuflauk5sKGmBe9ooiAojlAwb4aXiSU1WTiZ4ahIdN18z6o7hn9MpAqF4bHS5rZFNRudg/s1600/esProc_sql_fixedcriteria_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGzddXsNspRiPunGYA_1V5IR6vV-BE9bby8BwaLS8KHK0ipyEon-VJzf2fF0pMxVPPj6LzF5Uuflauk5sKGmBe9ooiAojlAwb4aXiSU1WTiZ4ahIdN18z6o7hn9MpAqF4bHS5rZFNRudg/s1600/esProc_sql_fixedcriteria_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In the above code, A2 contains strings which are separated from each other by commas and which represent a great number of fixed values conveniently.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Example 3</strong>:The list of potential client is the external parameters, like <span style="color: blue;">TAS, BON, CHO, ZTOZ</span>.</span><br />
<span style="font-family: inherit;">As the parameters change frequently, it is inconvenient to create a pseudo table using union statement in SQL. Alternatively, we have to create a temporary table, parse the parameters and insert the parsed parameters into this table for later computation. In esProc, it is unnecessary to create a temporary table for this case. The realization process is as follows:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">First, define a parameter <em>arg1</em>, as shown in the following figure:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJiBzQwshVWv3zSwxkRT6z1uDs_IItBiRUZTpvOtxoUv8d8C1n7-sBb8GdGsM0gQZJ3FIr1d4zX2azNE3jwcYTIr9fLhSsfmcXnTHrf-tSaunJUXeugv2yszkG5e_6RhsMG8xc9jRW4VM/s1600/esProc_sql_fixedcriteria_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJiBzQwshVWv3zSwxkRT6z1uDs_IItBiRUZTpvOtxoUv8d8C1n7-sBb8GdGsM0gQZJ3FIr1d4zX2azNE3jwcYTIr9fLhSsfmcXnTHrf-tSaunJUXeugv2yszkG5e_6RhsMG8xc9jRW4VM/s1600/esProc_sql_fixedcriteria_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">Then modify the script file, as shown below:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_E7uMnMRXdU3FFzDkoDx1HGroHwahIldSZStgKEB4_0fhhsoT1JZAOdqxIDlqZU-62BSceQCumnm4F1AAmUUCrEhrwqtJD1WxRpIBEuobQ7FeDwYcuuuGyO0ifbpqkMmw3o2GV_e8rI/s1600/esProc_sql_fixedcriteria_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_E7uMnMRXdU3FFzDkoDx1HGroHwahIldSZStgKEB4_0fhhsoT1JZAOdqxIDlqZU-62BSceQCumnm4F1AAmUUCrEhrwqtJD1WxRpIBEuobQ7FeDwYcuuuGyO0ifbpqkMmw3o2GV_e8rI/s1600/esProc_sql_fixedcriteria_8.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">Run the s esProc_sql_fixedcriteria_cript and enter the parameter values, which are assumed to be “TAS, BON, CHO, ZTOZ“, as shown below:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMQ-jtJb7a_hvZ520hRLI0kUOOZqGAUtl77KyhG4aStqVT1aVs3kNywOqz6OozLwybklAp0uRK2iE2uyOjWeifaFzNvB2YXNQaVksOAu3l5uLDz8KiJLBGv8KM01juQp_2Zr7XkarSIQ/s1600/esProc_sql_fixedcriteria_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIMQ-jtJb7a_hvZ520hRLI0kUOOZqGAUtl77KyhG4aStqVT1aVs3kNywOqz6OozLwybklAp0uRK2iE2uyOjWeifaFzNvB2YXNQaVksOAu3l5uLDz8KiJLBGv8KM01juQp_2Zr7XkarSIQ/s1600/esProc_sql_fixedcriteria_9.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Because the grouping criteria are the same as those in example 1, their final results are the same.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Note: The code in A2 converts the strings “<span style="color: blue;">TAS, BON, CHO, ZTOZ</span>” into the sequence <span style="color: blue;">["TAS","DSGC","GC","ZTOZ"]</span>. But this step of conversion can be omitted if the parameters are entered and <span style="color: blue;">["TAS","DSGC","GC","ZTOZ"]</span> is got directly.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Example 4</strong>:The criteria for the operation of data grouping with fixed criteria can be either the numerical values or conditions. For example, divide the order amounts into four sections by 1000, 2000 and 4000, with each section being a group of orders, and sum up the total amount of each group.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">If the criteria have been given, they can be fixed in SQL; if the criteria are the dynamic external parameters, high-level programming languages, like Java, should be used to write a program to compose a SQL statement and the process will be rather complicated. By supporting dynamic expressions, esProc can realize the operation in this example easily. The following shows the esProc code:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbonAMUBESzOlHqfO3AevQGZEy560C3aaidIliEFPo8QXKhes9DZ-524Zuz14DD52Ya8PYicxkdyK3bUCjfKXSPgcAmJ9xNQr9Vndpho1Jmt0LtaZAofgDqxUTtYfSZ6RJ04iYoRTNWa8/s1600/esProc_sql_fixedcriteria_10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbonAMUBESzOlHqfO3AevQGZEy560C3aaidIliEFPo8QXKhes9DZ-524Zuz14DD52Ya8PYicxkdyK3bUCjfKXSPgcAmJ9xNQr9Vndpho1Jmt0LtaZAofgDqxUTtYfSZ6RJ04iYoRTNWa8/s1600/esProc_sql_fixedcriteria_10.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">In the above code, the variable byFac represents the grouping criteria in this example, which include four string conditions. byFac can be external parameters, or a view or a table in a database as well. The final result of A4 s as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9gE0793aERoUNfR10D2UiixaOQKNOWepnNR6QzXdtDzgOg9T1Edj8Olp5MQ6Bb6xE9SUipSmUpguTePXfoEGOG3rR9sj4UH7NxYK08KTlVh8ot9blVyGd7nm5tWJUS0S0ain6bKKwnEI/s1600/esProc_sql_fixedcriteria_11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9gE0793aERoUNfR10D2UiixaOQKNOWepnNR6QzXdtDzgOg9T1Edj8Olp5MQ6Bb6xE9SUipSmUpguTePXfoEGOG3rR9sj4UH7NxYK08KTlVh8ot9blVyGd7nm5tWJUS0S0ain6bKKwnEI/s1600/esProc_sql_fixedcriteria_11.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Example 5</strong>:In the previous operations of conditional grouping, it happens that there are no overlapped conditions. But actually it is common to find that conditions overlap with each other. For example, group the order amounts according to the following conditions:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">1,000~4,000:Common orders <em>- r14</em></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Less than 2000:Non-important orders <em>- r2</em></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Above 3000:Important orders <em>- r3</em></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Here both <em>r2</em> and<em> r3</em> overlap with r14. In this case, if we don’t want the overlapped data, we can first select the data satisfying<em> r14</em> and then select from the rest of the data those satisfying <em>r2</em>, and so forth.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">esProc provides <em>enum</em> function to perform the conditional grouping whose conditions overlap with each other, as shown below:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0guMT1A4-NAP4Ww6U-VUgUezPLulan6ilhu4ASg9zcXmzXnd0osN9OZEKqf7GcyntqWedpC7drhkTIjP7JHTFqsfQtHolIUoVKvMEULjFNejxjVYwG9LfxHWWBNo1l6cxu_JEocr9cp4/s1600/esProc_sql_fixedcriteria_12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0guMT1A4-NAP4Ww6U-VUgUezPLulan6ilhu4ASg9zcXmzXnd0osN9OZEKqf7GcyntqWedpC7drhkTIjP7JHTFqsfQtHolIUoVKvMEULjFNejxjVYwG9LfxHWWBNo1l6cxu_JEocr9cp4/s1600/esProc_sql_fixedcriteria_12.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">The grouping result of A3 is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikOxYq7ndCiNCA_TVPDGZ3fPCPB4vJVEXosOxPiJvFwiREW4hjUWtmdSqiy3WlCXFKZPphrVTpatnmWtgx3hyg5r5_-dQBWH3Tml97_dmPvlOcNtG6njX3GfIo_ll_rGrg7O8SaZAStOU/s1600/esProc_sql_fixedcriteria_13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikOxYq7ndCiNCA_TVPDGZ3fPCPB4vJVEXosOxPiJvFwiREW4hjUWtmdSqiy3WlCXFKZPphrVTpatnmWtgx3hyg5r5_-dQBWH3Tml97_dmPvlOcNtG6njX3GfIo_ll_rGrg7O8SaZAStOU/s1600/esProc_sql_fixedcriteria_13.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">Computed result is as follows:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0to-b_19kD3B6YOUM_TslCcVUFx5LL2B9Lq2OqB9fQt5mZHyHSIH4Yf6JfxgUF-TayUm6Whjnqmm9glJblaLVpgx4hCv4pX0jRSD4lpq895Sulcnqk4GErqMKiorrjbZolVDfwwTghpY/s1600/esProc_sql_fixedcriteria_14.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0to-b_19kD3B6YOUM_TslCcVUFx5LL2B9Lq2OqB9fQt5mZHyHSIH4Yf6JfxgUF-TayUm6Whjnqmm9glJblaLVpgx4hCv4pX0jRSD4lpq895Sulcnqk4GErqMKiorrjbZolVDfwwTghpY/s1600/esProc_sql_fixedcriteria_14.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">But sometimes overlapped data is needed. For this purpose, data satisfying r14 will be selected from sales – one of the two groups of selected data mentioned above, and then data satisfying r2 will be selected from the original table of sales, and so forth. Here @r option will be used in enum function to modify the code in A3 into =sales.enum@r(byFac,Amount). Now the grouping result is as follows: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjskoiYU4ou4G1WY5O7VOOPSCYgYZ1NQVqO8ZSHgviPV6VwM3yuo3Ja6rFocdIp8oH7hRRTRqhi3LErtIJLdicoRKwehZ1RmRYKhiEes12uQ-ToQG3YNDtxaIsKKdaXp6RwcGAkAholAog/s1600/esProc_sql_fixedcriteria_15.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjskoiYU4ou4G1WY5O7VOOPSCYgYZ1NQVqO8ZSHgviPV6VwM3yuo3Ja6rFocdIp8oH7hRRTRqhi3LErtIJLdicoRKwehZ1RmRYKhiEes12uQ-ToQG3YNDtxaIsKKdaXp6RwcGAkAholAog/s1600/esProc_sql_fixedcriteria_15.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e; font-family: inherit;">In the above figure, the data in red boxes overlap with each other. The final computed result is as follows: </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimP50msK3rd2jn98XoRMm-cVB5sm_UhVti_4JBoQgYPyl60uJK_BrH2MUYr87TxTmjSSME6Gxd8UFcvhgGTMp3oLz6-QHpbPnP3G28JOGGlzJ1dXPFoE3Ca_ECoBoI5X_1HIQCpBLF0bk/s1600/esProc_sql_fixedcriteria_16.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimP50msK3rd2jn98XoRMm-cVB5sm_UhVti_4JBoQgYPyl60uJK_BrH2MUYr87TxTmjSSME6Gxd8UFcvhgGTMp3oLz6-QHpbPnP3G28JOGGlzJ1dXPFoE3Ca_ECoBoI5X_1HIQCpBLF0bk/s1600/esProc_sql_fixedcriteria_16.jpg" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In addition, esProc program can be called by the reporting tool or a Java program in a way similar to that in which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to the Java main program. For more details, please refer to the related documents.</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-56452631064029504392015-08-25T02:48:00.003-05:002015-08-25T02:48:29.672-05:00esProc Simplifies SQL-style Computations – Relational Computation on Groups<div style="color: #3e3e3e;">
<span style="font-family: inherit;">During developing database applications, we are often faced with complicated SQL-style computations like relational computation on multilayered groups. As SQL requires summarizing during data grouping and it doesn’t support object-style relational access, it is difficult to deal with these computations. We have to resort to an advanced technique of window functions nested with multilayered subqueries. esProc, however, can handle them more easily by supporting real grouping and visual object-style relational access.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In practice, there are a lot of cases in which relational computation on groups is needed, such as the one presented on the website <a href="http://forums.bit-tech.net/showthread.php?t=207052" style="text-decoration: none;">http://forums.bit-tech.net/showthread.php?t=207052</a>. Based on this practical example, we have designed a more common one for illustrating in detail how esProc works to realize the relational computation on groups.<strong> </strong></span></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Computing target</strong>: Query branches of a DVD store where there are less than four categories of DVD copies.<strong> </strong></span></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Data Structure</strong>:Branch Table stores information of the branch stores. DVD Table stores titles and categories of DVDs, in which DVDs, like <em>Transformers IV</em>, are virtual data items instead of physical disks. DVDCopy Table stores physical DVD copies branch stores have. Note: DVDCopy Table is related to Branch Table through BranchID field, and to DVD Table through DVDID field. The following is part of the data:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Branch Table:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKl1nuBCU6cCfqkdvGEVLu9mID8auMxLivhXME0RR_xCJdz-4WovJmuhK-SixlnvADb7-3RRgpqFCT4yCCkEWUNe-Mxp3MDit7LEsHO5Ds7KY71dv2V9f6WRGguz8TrVTNGtbxeD5Igkw/s1600/esProc_sql_relationalgroup_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKl1nuBCU6cCfqkdvGEVLu9mID8auMxLivhXME0RR_xCJdz-4WovJmuhK-SixlnvADb7-3RRgpqFCT4yCCkEWUNe-Mxp3MDit7LEsHO5Ds7KY71dv2V9f6WRGguz8TrVTNGtbxeD5Igkw/s1600/esProc_sql_relationalgroup_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">DVD Table:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZes-OW7S8q1Y1Mhr2Jxm2UGMAT6CbpzrN19wkUyoVbSnYcdEoznGL3pVdGr5y-dTBOBXZa5c55acrzzUwRSrX_mxQ_fDVvN2I5-bZLpqSb8tAuqyCdirN6a7bojFLNhAdMc5j3gzgbO0/s1600/esProc_sql_relationalgroup_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZes-OW7S8q1Y1Mhr2Jxm2UGMAT6CbpzrN19wkUyoVbSnYcdEoznGL3pVdGr5y-dTBOBXZa5c55acrzzUwRSrX_mxQ_fDVvN2I5-bZLpqSb8tAuqyCdirN6a7bojFLNhAdMc5j3gzgbO0/s1600/esProc_sql_relationalgroup_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">DVDCopy Table:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoqJ6SjZ72Tt4J4jJbQp6UemAB3O-1g8yWIozLO96E2lqOmBzeOcVQeQIrJ2d7zmX19V3rbk-NSz1vRaPxCPW85xSxQz_ozU8ANq094LK1ANnl2SuM_y-5eDihWfl5PqfXq1E-6L5CaE/s1600/esProc_sql_relationalgroup_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoqJ6SjZ72Tt4J4jJbQp6UemAB3O-1g8yWIozLO96E2lqOmBzeOcVQeQIrJ2d7zmX19V3rbk-NSz1vRaPxCPW85xSxQz_ozU8ANq094LK1ANnl2SuM_y-5eDihWfl5PqfXq1E-6L5CaE/s1600/esProc_sql_relationalgroup_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Description:<br />1. Computed results should be certain records in Branch Table.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">2. That the Status field of a record in DVDCopy shows Miss means the DVD is missing, and that a record’s LastDateReturned field is empty means the DVD has been rented out but not returned. Obviously the DVDs that are missing and haven’t been returned are outside of our computing objects and should be filtered away.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">3. We should consider the situation that there may be certain branch stores whose information isn’t included in DVDCopy Table, though it is rarely seen.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Solution:<br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">1. Select valid, existing DVD copies the branch stores have from DVDCopy Table.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">2. Group DVDCopy Table by BID. Each group will contain all DVD copies a branch store has.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">3. Select the DVDs corresponding to the DVD copies each branch store has, and compute the number of categories to which these DVDs belong.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">4. Select branch stores where the number of categories of existing DVDs is less than four. These branch stores are eligible.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">5. Select branch stores which DVDCopy Table hasn’t. They are also eligible.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">6. Combine the two kinds of eligible branch stores.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Code written in esProc:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtWlXwHYBOd8Kfg5LFxmzJPgau_8UB01W7HTuxW3_dxy2Cp9A4yCpJSHOg1wV4BkTtZCBZOMzaoHDjugmEPI7TXyPrSvOpyRkDXKVzUR5cY3Cx4Epz3qTl7UPdpQO8qFfFuTTMpZSwZI4/s1600/esProc_sql_relationalgroup_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtWlXwHYBOd8Kfg5LFxmzJPgau_8UB01W7HTuxW3_dxy2Cp9A4yCpJSHOg1wV4BkTtZCBZOMzaoHDjugmEPI7TXyPrSvOpyRkDXKVzUR5cY3Cx4Epz3qTl7UPdpQO8qFfFuTTMpZSwZI4/s1600/esProc_sql_relationalgroup_4.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1-A3:Query data from three tables in the database. The three tables are made variables which are named respectively as Branch, DVD and DVDCopy. Computed results are as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6zbcB49jVp4_FoX7kb7MRZhqyCVowe_eAOpGfu8p37mQl5q68PBzrDy46qd6xCWfHKIeAJOU8ECJhcmTklEmEMUhv1XhtKLJvDvtNg126k5mlrC2oCE8egB04Rf8hwY1_QswfgVyKkbA/s1600/esProc_sql_relationalgroup_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6zbcB49jVp4_FoX7kb7MRZhqyCVowe_eAOpGfu8p37mQl5q68PBzrDy46qd6xCWfHKIeAJOU8ECJhcmTklEmEMUhv1XhtKLJvDvtNg126k5mlrC2oCE8egB04Rf8hwY1_QswfgVyKkbA/s1600/esProc_sql_relationalgroup_5.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A4: Switch the DVDID field and BID field in DVDCopy Table to corresponding records in DVD Table and Branch Table respectively. Note: This step is the basis of object-style relational access, which requires the use of switch function. After computing, DVDCopy becomes as follows:</span></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57ls8UZB9gfW7aOAQzgxiKjp1r90D1Jeib9Bs_fGb3877DigM0hBw77scl6RnXTWnt7Avi5TqlT-wudPMMR4DPffWuWiwQydtYiw6k81DIJbhPBI-oWbtXe1iQXtwRFDWO-cbVRccUYA/s1600/esProc_sql_relationalgroup_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57ls8UZB9gfW7aOAQzgxiKjp1r90D1Jeib9Bs_fGb3877DigM0hBw77scl6RnXTWnt7Avi5TqlT-wudPMMR4DPffWuWiwQydtYiw6k81DIJbhPBI-oWbtXe1iQXtwRFDWO-cbVRccUYA/s1600/esProc_sql_relationalgroup_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">Fields in blue have corresponding records. Click one and you can see the details, as shown in the following figure:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrRXzvagYV9xuo4XDazD2zhXu7fTrSTbqkExM6UIUYJzNLSENcX8bPPxlz8tw8w_lXk35aTDMoTuz0y5sbZj5c_zTuNop_BkLmRAQgOGkEyrEUlYJ8ZpRYzRv_Z6Fo7-atvJVa9QJhi8w/s1600/esProc_sql_relationalgroup_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrRXzvagYV9xuo4XDazD2zhXu7fTrSTbqkExM6UIUYJzNLSENcX8bPPxlz8tw8w_lXk35aTDMoTuz0y5sbZj5c_zTuNop_BkLmRAQgOGkEyrEUlYJ8ZpRYzRv_Z6Fo7-atvJVa9QJhi8w/s1600/esProc_sql_relationalgroup_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Now we can perform object-style relational access only with the operator “.”. For instance, <span style="color: blue;">DVDCopy.(DVDID)</span>. <span style="color: blue;">(Category)</span> represents the category of each DVD copy, and <span style="color: blue;">DVDCopy.(BID)</span> gets the detailed information (complete record) about the branch store corresponding to each DVD copy.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A5:<span style="color: blue;">=DVDCopy.select(Statues!=”Miss” && LastDateReturend!=null)</span>. This line of code aims to filter away the DVD copies that are missing and that haven’t been returned. After the code is executed, values of A5 are shown as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWXndLRJpCpsy_zZN0_fLGK6g8U-QM5v2-TYGPuLVGPIwZAs3Mo33w5snOEeUhQnUjFL6NhNZNLXgLUp1FxzWjl0h8DBH-0TprKL_MBGW8cLJnzKrY6E8UcWCFD5Ojoupjld1z2yTEykc/s1600/esProc_sql_relationalgroup_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWXndLRJpCpsy_zZN0_fLGK6g8U-QM5v2-TYGPuLVGPIwZAs3Mo33w5snOEeUhQnUjFL6NhNZNLXgLUp1FxzWjl0h8DBH-0TprKL_MBGW8cLJnzKrY6E8UcWCFD5Ojoupjld1z2yTEykc/s1600/esProc_sql_relationalgroup_8.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A6:=A5.group(BID) is to group data in A5 by BID, with each row representing all DVD copies a branch store has. The result is as follows:</span></span><br />
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioWAiYWAW_7_-HxPHv5id7wEKAhZd3M_zdiEi9ENrUvd1Xp89QNHOaVNJ2Lb0pFDnPCSSCP0wdyVfsyASJFiAZZftpfAYeYdjYZM9S81TR18nS7ORuZWmV3NaH7BzY_SsCy-5X1sKAt3I/s1600/esProc_sql_relationalgroup_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioWAiYWAW_7_-HxPHv5id7wEKAhZd3M_zdiEi9ENrUvd1Xp89QNHOaVNJ2Lb0pFDnPCSSCP0wdyVfsyASJFiAZZftpfAYeYdjYZM9S81TR18nS7ORuZWmV3NaH7BzY_SsCy-5X1sKAt3I/s1600/esProc_sql_relationalgroup_9.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">Click the data in blue and you’ll see members of each group:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnU_vqzwPJOttM0WRagngenH7ibAIEsB7GOEeHGlz7SPiZgB8Y2N0obDI0CpTH6qUbajmDPydakv3mu0nmj3yfg168wMPxElzdaSa2vfJ5haPIpoxTyfPmg-neSPdX-InoWRPREs0XdQY/s1600/esProc_sql_relationalgroup_10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnU_vqzwPJOttM0WRagngenH7ibAIEsB7GOEeHGlz7SPiZgB8Y2N0obDI0CpTH6qUbajmDPydakv3mu0nmj3yfg168wMPxElzdaSa2vfJ5haPIpoxTyfPmg-neSPdX-InoWRPREs0XdQY/s1600/esProc_sql_relationalgroup_10.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">It can be seen that<strong> group</strong> function only groups data, but doesn’t summarize the data at the same time. In this point, it is different from the function for grouping in SQL. Sometimes, we need to further process the grouped data, rather than simply summarizing them. To do this, esProc’s <strong>group</strong> function is more convenient to use, as shown in the code in A7:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A7:<span style="color: blue;">=A6.new( ~.BID:BonList, ~.(DVDID).id(Category).count():CatCount )</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The above line of code computes the number of categories of DVD copies to which each branch store corresponds. <strong>new</strong> function can generate a new object A7 based on the data in A6. A7 has two columns: BonList and CatCount. BonList originates directly from column BID of the grouped data in A6, and CatCount originates from column DVDID of the grouped data. There are three steps to compute CatCount:<span style="color: blue;"> ~.(DVDID)</span> finds the DVD records corresponding to all DVD copies each branch store has; id<span style="color: blue;">(Category)</span> removes repeated records of Category from these DVD records; and count() computes the number of categories. The result is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3Y54-jWxk8Hw3ruk0gKcomJDegxM6TOzgo884nHmRDJr5vMMK7rf22ZRqT2DCY4SDSUuqeImXZLm22KHXhhxBmIbJoVVW2ZOz4FzXfxYCe-r59iMoyDq69kcWcidHzAa5QXRfFqC7MnU/s1600/esProc_sql_relationalgroup_11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3Y54-jWxk8Hw3ruk0gKcomJDegxM6TOzgo884nHmRDJr5vMMK7rf22ZRqT2DCY4SDSUuqeImXZLm22KHXhhxBmIbJoVVW2ZOz4FzXfxYCe-r59iMoyDq69kcWcidHzAa5QXRfFqC7MnU/s1600/esProc_sql_relationalgroup_11.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">That is, branch store B002 has three categories of DVD copies, B003 also has three categories and B001 has four categories.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A8:<span style="color: blue;">A7.select(CatCount). <span style="color: black;">This line of code makes query to select branch stores whose <em>CatCount</em> is less than 4. The result is as follows:</span></span></span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoJtDTtFNuUM_iAuhmU877XxnENw17JfWcdq3dT8LsH60tqbWeZgWtSOjX0SRN5r6VRc_k8tKN3F557JtzXJifkIB8uCl3M8ABXOu7MlBFCZy8L0w1txVndUSsduyOHGuoRgQm6hpDoVk/s1600/esProc_sql_relationalgroup_12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoJtDTtFNuUM_iAuhmU877XxnENw17JfWcdq3dT8LsH60tqbWeZgWtSOjX0SRN5r6VRc_k8tKN3F557JtzXJifkIB8uCl3M8ABXOu7MlBFCZy8L0w1txVndUSsduyOHGuoRgQm6hpDoVk/s1600/esProc_sql_relationalgroup_12.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The above branch stores that are in short supply are computed according to DVDCopy Table. But maybe some branch stores with serious supply shortage are not in the DVDCopy, such as the cases that all the DVD copies in the branch store has been rented out, or that the branch store hasn’t any DVD copies. So these branch stores should also be counted. The code for this step is as follows:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A9:<span style="color: blue;">=A8.(BonList) | (Branch \ A7.(BonList))</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In the above code, operator “|” represents the union operation of two data sets (which can be replaced by <strong>union</strong> function); operator “\” represents the complement operation (which can be replaced by<strong> diff</strong> function).<span style="color: blue;"> A8.(BonList)</span>,<span style="color: blue;"> Branch</span> and<span style="color: blue;"> A7.(BonList)</span> represent respectively branch stores with supply shortage in DVDCopy Table, all branch stores and branch stores which are included in DVDCopy Table. Their respective values are:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSgEnByYMersDsG1ljBx2eDsMPJ5VFKw6LCAZzUDwuh4cDWmja-WEXvlP1Tr4t3WaY7ngIGiP-WCZhS2AOWbEhlPkfUcvjHhUtQAWj8o4PPxwQS-29LoTjFP879vC_owbMSuAJy2YZ6uw/s1600/esProc_sql_relationalgroup_13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSgEnByYMersDsG1ljBx2eDsMPJ5VFKw6LCAZzUDwuh4cDWmja-WEXvlP1Tr4t3WaY7ngIGiP-WCZhS2AOWbEhlPkfUcvjHhUtQAWj8o4PPxwQS-29LoTjFP879vC_owbMSuAJy2YZ6uw/s1600/esProc_sql_relationalgroup_13.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A9 computes the final result of this example. Its values are:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGIP2g11dX9aGzEEAhJt9LGPwpuyJFIzO3RoES6qK3goAxQ9eSeQzDSU7b1ydZsqXQCB_JHUi0qtc8nuNSPaatDigPWX8NxSRft9qZFW_thuEd8HuqysBEc2ipp095Otcrh0UHPYRS3yk/s1600/esProc_sql_relationalgroup_14.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGIP2g11dX9aGzEEAhJt9LGPwpuyJFIzO3RoES6qK3goAxQ9eSeQzDSU7b1ydZsqXQCB_JHUi0qtc8nuNSPaatDigPWX8NxSRft9qZFW_thuEd8HuqysBEc2ipp095Otcrh0UHPYRS3yk/s1600/esProc_sql_relationalgroup_14.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Or we can realize the computation indirectly. For instance, first compute “branch stores that are not in short supply”, and then compute the complement of the result and Branch Table. The final result should be the same as that of A9.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Please note variables like A8 or Branch cannot be used to represent a data set in SQL because it doesn’t support explicit set. Thus the simple code in the above have to be replaced by lines of complicated SQL statements.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Besides, esProc can be called by a Java program. The method is similar to that with which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to Java main program. For more details, please refer to the related documents .</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-52889480102772786132015-08-24T01:07:00.000-05:002015-08-24T01:07:06.314-05:00esProc Simplifies SQL-style Computations – Records Corresponding to Max Value<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In developing database applications, usually it is the records corresponding to the max/min value that we need to retrieve, instead of the value itself. For example, the occasion in which each employee gets his/her biggest pay raise; the three lowest scores ever got in golf; the five days in each month when each product gets its highest sales amount; and so on. As the <em>max</em> function of SQL can only retrieve the max value, instead of the records to which the max value corresponds, it is quite complicated to handle the computation in SQL with the aid of some advanced techniques, such as window functions or the nested sub-queries or keep/top/row number. If multi-layered grouping or relations are involved, the computation will become even more complicated.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">With the <em>top</em> function in esProc, the records corresponding to the max value can be retrieved and the computation becomes much easier. The following is such an example.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The database table <em>golf</em> contains the scores of members in a golf club. Please select the best three scores each member has ever got. Part of the data is as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeEeBUKkcySd5kYwIL3Qs67QChdje5TWFJYYKrgMdnyj4GRx_rXOFZkmcfXlfPC-0DiCF_fdg5CSA3TKnEgX2QymxherO-yZusu2YznQrYhqpRCAheiOaGv4NxcQVqyBnzCdTumGzvxSg/s1600/esProc_sql_maxvalue_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeEeBUKkcySd5kYwIL3Qs67QChdje5TWFJYYKrgMdnyj4GRx_rXOFZkmcfXlfPC-0DiCF_fdg5CSA3TKnEgX2QymxherO-yZusu2YznQrYhqpRCAheiOaGv4NxcQVqyBnzCdTumGzvxSg/s1600/esProc_sql_maxvalue_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">The code written in esProc:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlfRDqUSEtH_Od32kcmage4ukEdZRQFO-VOb_yVgWklrzb3orh0YnbFgJgVM6Ca_50Twc3DLsF4Yp8INCvH63S4kxR1j0504slUKJuJkQpNNCU4EoczuurUu2Ts0dFumH2XMJRCdx3o9Q/s1600/esProc_sql_maxvalue_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlfRDqUSEtH_Od32kcmage4ukEdZRQFO-VOb_yVgWklrzb3orh0YnbFgJgVM6Ca_50Twc3DLsF4Yp8INCvH63S4kxR1j0504slUKJuJkQpNNCU4EoczuurUu2Ts0dFumH2XMJRCdx3o9Q/s1600/esProc_sql_maxvalue_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">A1: Retrieve data from the database. If the data come from a structured text file, the following equivalent code can be used: =file(“\\golf”).import@t(). Click the cell and we can check the retrieving result: </span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS7oWQ8RlajPam8iD5kgNGtt9r3Czkby00sJyFVbK0aa0_sp2-jvp_6BgPH8uaTPZb_RB_OvgtIoYQ_HsSyfHJwDjM_szX8anaRr7L3Qc8d82esHr_2lxn-3lANOm6MSLZerkxVZI6Jls/s1600/esProc_sql_maxvalue_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS7oWQ8RlajPam8iD5kgNGtt9r3Czkby00sJyFVbK0aa0_sp2-jvp_6BgPH8uaTPZb_RB_OvgtIoYQ_HsSyfHJwDjM_szX8anaRr7L3Qc8d82esHr_2lxn-3lANOm6MSLZerkxVZI6Jls/s1600/esProc_sql_maxvalue_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">A2:=A1.group(User_ID), i.e., group the result of A1. The result is as follows: </span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVnFwjGgMVsw9EkO2JkOxDTEmZez4rq1DdS3q8cQ_vonaZ-yOnMnqek5TDHZiWjIa48rquUpPEoqhc_wYqznuaCali2ZkAPpKS_6d_TRKs16vgoPgm9_x-GGCvRkmmdLYjFVDYKJEEdEs/s1600/esProc_sql_maxvalue_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVnFwjGgMVsw9EkO2JkOxDTEmZez4rq1DdS3q8cQ_vonaZ-yOnMnqek5TDHZiWjIa48rquUpPEoqhc_wYqznuaCali2ZkAPpKS_6d_TRKs16vgoPgm9_x-GGCvRkmmdLYjFVDYKJEEdEs/s1600/esProc_sql_maxvalue_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">As shown in the above figure, the data have been separated into multiple groups by User_ID and each row is a group. Click the blue hyperlink and members of the group will be shown as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitDbWs6Q7HbAAjeRXB3JB3UQZF3Mke1OG9TrZzH7ger3YauBAx-asnc-IlC37IFjTKtHdyLC75DXzozAE5JpB0_bkt1Js9qsFW4wwE_rkSZNdbSmrEs673MpIE2UupQFx3dYBaWv-xDw0/s1600/esProc_sql_maxvalue_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitDbWs6Q7HbAAjeRXB3JB3UQZF3Mke1OG9TrZzH7ger3YauBAx-asnc-IlC37IFjTKtHdyLC75DXzozAE5JpB0_bkt1Js9qsFW4wwE_rkSZNdbSmrEs673MpIE2UupQFx3dYBaWv-xDw0/s1600/esProc_sql_maxvalue_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A3:=A2.(~.top(-Score;3)). The code is to compute the records of each group of data whose field Score is in the top three. Here “~” represents each group of data. ~.top() represents that top function will work on every group of data in turn. The top function can retrieve the N biggest/smallest records from a data set. For example, top(Score;3) represents sorting by Score in ascending order and fetching the first three records (i.e. min values); top(-Score;3) represents sorting in descending order and fetching the first three records (i.e. max values). The result of this step is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2ubPDKqudCvVUM8kgSQ5OwN3GKXsSQreC5qLVcBQ9d0yfLTcASNLESYhFLYACnDtsD1wYLdBqOnt7Nx51KuDcVarivoJmP7nPvDAug-qe8Vb1TSu-CvLM0axOHRbuU6hrp9xRL9kjtx8/s1600/esProc_sql_maxvalue_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2ubPDKqudCvVUM8kgSQ5OwN3GKXsSQreC5qLVcBQ9d0yfLTcASNLESYhFLYACnDtsD1wYLdBqOnt7Nx51KuDcVarivoJmP7nPvDAug-qe8Vb1TSu-CvLM0axOHRbuU6hrp9xRL9kjtx8/s1600/esProc_sql_maxvalue_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A4:=A3.union(), which means union data of every group. The result is as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh6MIKz2U7lVGCoa89PeFVndCOlxhWxdj8fg1hWIto5ZSZAlVD33uVck-7bg7ocaHMdP5vXt2heSE2XbETuni_Oojk5EUiooNjk5Tgd3oVb2NHGUWUQgFEbgETFZH-YBGMOqKheHfP5C4/s1600/esProc_sql_maxvalue_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh6MIKz2U7lVGCoa89PeFVndCOlxhWxdj8fg1hWIto5ZSZAlVD33uVck-7bg7ocaHMdP5vXt2heSE2XbETuni_Oojk5EUiooNjk5Tgd3oVb2NHGUWUQgFEbgETFZH-YBGMOqKheHfP5C4/s1600/esProc_sql_maxvalue_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In the above, the computation is performed step by step. But the steps can be integrated into one for the convenience of maintenance and debugging: <span style="color: blue;">db.query(“select * from golf”).group(User_ID). (~.top(-Score;3)).union()</span>.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The method with which a Java program calls esProc is similar to that with which it calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to Java main program. For more details, please refer to the related documents .</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-63918159617791258022015-08-21T00:50:00.003-05:002015-08-21T00:50:47.021-05:00esProc Simplifies SQL-style Computations–In-group Computation<div style="color: #3e3e3e;">
<span style="font-family: inherit;">During developing the database applications, we often need to perform computations on the grouped data in each group. For example, list the names of the students who have published papers in each of the past three years; make statistics of the employees who have taken part in all previous training; select the top three days when each client gets the highest scores in a golf game; and the like. To perform these computations, SQL needs multi-layered nests, which will make the code difficult to understand and maintain. By contrast, esProc is better at handling this kind of in-group computation, as well as easy to integrate with Java and the reporting tool. We’ll illustrate this through an example.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">According to the database table <em>SaleData</em>, select the clients whose sales amount of each month in the year 2013 is always in the top 20. Part of the data of <em>SalesData</em> is as follows:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOqZ2-cH4IMqNv0lNWzusR3GFnAne9iGKPrORLM1XljasqDSV8lmpdC07iCYRiWflpcKTUVjcqQgQTZMqI0LIt2XPt3yp_VfSkl9583h42P_DRPgLesdfUPQ9FYeMsIoE5s974qyxJikg/s1600/esProc_sql_ingroup_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOqZ2-cH4IMqNv0lNWzusR3GFnAne9iGKPrORLM1XljasqDSV8lmpdC07iCYRiWflpcKTUVjcqQgQTZMqI0LIt2XPt3yp_VfSkl9583h42P_DRPgLesdfUPQ9FYeMsIoE5s974qyxJikg/s1600/esProc_sql_ingroup_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">To complete the task, first select the sales data of the year of 2013, and then group the data by the month and, in each group, select the clients whose monthly sales amount is in the top 20. Finally, compute the intersection of these groups.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">With esProc we can split this complicated problem into several steps and then get the final result. First, retrieve the data of 2013 from SaleData and group it by the month:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWKSjTui8X7VSiOr9fvv5p1bYRr6PqG6jnV9j9sFG1U75Hbi10oKyf1rLHWajyhoTrtpFZ4aLTRbcdP3rlWDfrDJFbcJ1JixIjVVq4mtXwbrUYhGBt6IiKHMJQkpqj7n4gU8AsDZy5AXQ/s1600/esProc_sql_ingroup_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWKSjTui8X7VSiOr9fvv5p1bYRr6PqG6jnV9j9sFG1U75Hbi10oKyf1rLHWajyhoTrtpFZ4aLTRbcdP3rlWDfrDJFbcJ1JixIjVVq4mtXwbrUYhGBt6IiKHMJQkpqj7n4gU8AsDZy5AXQ/s1600/esProc_sql_ingroup_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Note: The code for filtering in A2 can also be written in SQL.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">It is the<strong> real grouping</strong> that esProc separates data into multiple groups. This is different from the case in SQL, whose <em>group by</em> command will compute the summary value of each group directly and won’t keep the intermediate results of the grouping. After grouping, the data in A3 are as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMv4-VCWgruw01q7qb9On8HNtdwe4EPHOhfexYhoi-wIDVam1O3iPTGKNHrhpMNlL1GcEAupo9dGXweZIh-4vpFSOLJljGnksZpHrU3Fq_u9ytDYwEVHnnb-cTLwSw6EE4g2HinV9LM08/s1600/esProc_sql_ingroup_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMv4-VCWgruw01q7qb9On8HNtdwe4EPHOhfexYhoi-wIDVam1O3iPTGKNHrhpMNlL1GcEAupo9dGXweZIh-4vpFSOLJljGnksZpHrU3Fq_u9ytDYwEVHnnb-cTLwSw6EE4g2HinV9LM08/s1600/esProc_sql_ingroup_3.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">esProc will sorts the data automatically before grouping. Each group is a set of sales data. The data of March, for example, are as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW9CZmoWqWT-Bi8pc3bapsqvxH5_wjT4t4nQSm1Ud5kQ2EN9X7hpLOCEuvjafUrpw9vWgZf6sOqH4itCOnmRMIzENTWmu3DDXXpOW-caZQDL3UPO3vwuDkfjLEDKidRM_RC-GxOPe7lqI/s1600/esProc_sql_ingroup_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW9CZmoWqWT-Bi8pc3bapsqvxH5_wjT4t4nQSm1Ud5kQ2EN9X7hpLOCEuvjafUrpw9vWgZf6sOqH4itCOnmRMIzENTWmu3DDXXpOW-caZQDL3UPO3vwuDkfjLEDKidRM_RC-GxOPe7lqI/s1600/esProc_sql_ingroup_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In order to compute every client’s sales amount of each month, we need to group the data a second time by clients. In esProc, we just need to perform this step by looping the data of each month and group it respectively.<strong> A.(x) can be used to execute the loop on members of a certain group, with no necessity for loop code.</strong></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A4:<span style="color: blue;">=A3.(~group(Client))</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In A4, the data of each month constitute <strong>a subgroup of each previous group</strong> after the second grouping:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzyt6MEBoRy7AObpwnxoVHPo8Gc8lGyU08KNjnkSvEt7zZ5IrjcCeqlZK67LDZZmAZJdDS3R8DDI3XiQC_5BglW0cIMCNXZswp194i_SKfaxPJ8_fPgRVcY3QQ6sLIcN1fQhOcdiZK6d0/s1600/esProc_sql_ingroup_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzyt6MEBoRy7AObpwnxoVHPo8Gc8lGyU08KNjnkSvEt7zZ5IrjcCeqlZK67LDZZmAZJdDS3R8DDI3XiQC_5BglW0cIMCNXZswp194i_SKfaxPJ8_fPgRVcY3QQ6sLIcN1fQhOcdiZK6d0/s1600/esProc_sql_ingroup_5.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">At this point, the data of March are as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEyWAJI2nW7X3wGULmkR5Z6YI-edf-fJvOEJArfGW5U7ArRJrc8EKVjXoqBAhPYJmgl1P2T2g5TqKoA2vgIIF9ZxIux5w953VRohou6GcgdzVN4Al_BmpTugK8onb8J_RrTCtO_87R0mo/s1600/esProc_sql_ingroup_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEyWAJI2nW7X3wGULmkR5Z6YI-edf-fJvOEJArfGW5U7ArRJrc8EKVjXoqBAhPYJmgl1P2T2g5TqKoA2vgIIF9ZxIux5w953VRohou6GcgdzVN4Al_BmpTugK8onb8J_RrTCtO_87R0mo/s1600/esProc_sql_ingroup_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">It can be seen that each group of data in March contains the sales data of a certain client.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Please note <span style="color: blue;">“~”</span> in the above code represents each member of the group, and the code written with “~” is called in-group computation code, like the above-mentioned<span style="color: blue;"> ~.group(Client)</span>.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Next, select the clients whose rankings of each month are in the top 20 through the in-group computation:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A5:=A4.(~.top(-sum(Amount);20))</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A6:=A5.(~.new(Client,sum(Amount):MonthAmount))</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A5 computes the top 20 clients of each month in sales amount by looping each month’s data. A6 lists the clients and their sales amount every month. The result of A6 is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjnjPEanI-wQX_qyoeRrEbLGehhRLAYlAcvPoU3hTZ6-iNGmoEkMzTTsMqK_nDRxnMDRrBx_XWxmZ1ZdeClSiL9wAUgc9ivpinAFgMkIQVZ3nZIuRTdkF-IyWOAQCk7FUrZrci-Q5yGnY/s1600/esProc_sql_ingroup_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjnjPEanI-wQX_qyoeRrEbLGehhRLAYlAcvPoU3hTZ6-iNGmoEkMzTTsMqK_nDRxnMDRrBx_XWxmZ1ZdeClSiL9wAUgc9ivpinAFgMkIQVZ3nZIuRTdkF-IyWOAQCk7FUrZrci-Q5yGnY/s1600/esProc_sql_ingroup_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Finally, list the field Client of each subgroup and compute the intersection of the subgroups:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A7:=A6.(~.(Client))</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A8:=A7.isect()</span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A7 computes the top 20 clients of each month in sales amount. A8 computes the intersection of the field Clients of the twelve months. The result is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTXkBumvxq_sqJ_O8Epl7WIuph-Ex-sYzLUiIGT3GJnelwwcd0XtX1lIcp4BEFKqs-1stPyxqOc7eGactcvAnYp-wbUVJYm4QFcKSjElzy0txOMWne-YXQFdMNZsbbb3h_sH1wDgqrj94/s1600/esProc_sql_ingroup_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTXkBumvxq_sqJ_O8Epl7WIuph-Ex-sYzLUiIGT3GJnelwwcd0XtX1lIcp4BEFKqs-1stPyxqOc7eGactcvAnYp-wbUVJYm4QFcKSjElzy0txOMWne-YXQFdMNZsbbb3h_sH1wDgqrj94/s1600/esProc_sql_ingroup_8.jpg" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">As can be seen from this problem, esProc can easily realize the in-group computation, including the second group and sort, on the structured data, make the solving way more visually, and display a clear and smooth data processing in each step. Moreover, the operations, like looping members of a group or computing intersection, become easier in esProc, which will reduce the amount of code significantly.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The method with which a Java program calls esProc is similar to that with which it calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to Java main program. For more details, please refer to the related documents .</span></div>
<br />Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-82268493769098770382015-08-20T01:35:00.003-05:002015-08-20T01:35:31.486-05:00esProc Simplifies SQL-style Computations – Arrange Multilayered Data in One Column<span style="color: #3e3e3e;"><span style="font-family: inherit;">We are often confronted with complicated SQL-style computations during developing data base applications. For instance, arrange grouped data into one column in certain order, making marks for different types of groups and detail data, as shown in the following: </span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikL2MuPe9GgCMjLxH7G1xkqcYAaThWOSyCLqqy8qtCnUWi5lAi7NVId_QemzeqfiyWwsiYB_qCahuAERI4eujWLTJ9f7sZRGAvzZ8Zd02lt6FCxjkjDEsq_NPExFjBvxvsui42VW8qJsg/s1600/esProc_simplifies_sql_column_data_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikL2MuPe9GgCMjLxH7G1xkqcYAaThWOSyCLqqy8qtCnUWi5lAi7NVId_QemzeqfiyWwsiYB_qCahuAERI4eujWLTJ9f7sZRGAvzZ8Zd02lt6FCxjkjDEsq_NPExFjBvxvsui42VW8qJsg/s1600/esProc_simplifies_sql_column_data_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This kind of operation is commonly seen in organizing report data. As SQL lacks the mechanism of ordered sets, we need to create computed columns for sorting based on group and detail data, combine the group and the detail data together and finally sort them. Usually, special SQL functions of non-ANSI standard are used to realize the operation, which complicates the code writing and produces difficult-to-understand code. The operation will be made even more difficult if we try to combine multilayered groups together.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">However, we can use esProc to perform this kind of operation without creating computed columns and with concise and simple code. The method will be explained in detail through the following example.</span></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;">Computing target:</span></strong></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Arrange the branch stores and their corresponding DVD copies in one column according to DVDCopy table.<br /><strong></strong></span></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><strong>Data Structure:</strong><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">The first three fields of DVD table are CopyID, DVDID and BID, which represent the ID numbers of DVD copies, DVDs and branch stores respectively. There is a many-to-one relationship between DVD copies and a branch store. Part of the data is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjX-40LyirKGuJLIvkfQLyYetVIzsZfGh7FLLI-JMIvKtA79FCce8RjcgrzdhpUApoTW3vfPmylJTlYcyKXnNdIT7ztCg3dCHym7JsqKgzwc1uCjxYIr8Fq4JrknH1oECGs_grbFLEVvjs/s1600/esProc_simplifies_sql_column_data_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjX-40LyirKGuJLIvkfQLyYetVIzsZfGh7FLLI-JMIvKtA79FCce8RjcgrzdhpUApoTW3vfPmylJTlYcyKXnNdIT7ztCg3dCHym7JsqKgzwc1uCjxYIr8Fq4JrknH1oECGs_grbFLEVvjs/s1600/esProc_simplifies_sql_column_data_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">The computed result should be like this:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5kJZ3jJe54R066drWMX0FWWjIX1KOt3qPA59riVZj0PSGL9m2nqXBhiArnzUazpZouHvFjmgtYGrayBbefzKVGMSkvmKdjE4bRYJDIu6_u7wV3HdV5Nd24QoH8rhb46_CzN8WslBo-cQ/s1600/esProc_simplifies_sql_column_data_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5kJZ3jJe54R066drWMX0FWWjIX1KOt3qPA59riVZj0PSGL9m2nqXBhiArnzUazpZouHvFjmgtYGrayBbefzKVGMSkvmKdjE4bRYJDIu6_u7wV3HdV5Nd24QoH8rhb46_CzN8WslBo-cQ/s1600/esProc_simplifies_sql_column_data_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">Code written in esProc:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_93K_Vm9lsLqsQER4a0kkJMFdGGkIV5IYI9giALxZUSnodcUGxsnRBATwxEbOZ1L28o4az-sg1-YLVV29C57P1tafi33lQsOeYEVzGBncG4-ct8AeWzs-zPdQi12aSe_vzAnbzYPs63I/s1600/esProc_simplifies_sql_column_data_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_93K_Vm9lsLqsQER4a0kkJMFdGGkIV5IYI9giALxZUSnodcUGxsnRBATwxEbOZ1L28o4az-sg1-YLVV29C57P1tafi33lQsOeYEVzGBncG4-ct8AeWzs-zPdQi12aSe_vzAnbzYPs63I/s1600/esProc_simplifies_sql_column_data_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">A1: Retrieve data from the database and sort them by BID field. The result is as follows:</span></span><br />
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0vnono2qS90OK30hrXDaq_zKnjyXUzbgm8Y2usTVVrEgE69vb1LM-0iORsstbqvpr7vX3DJK42qAU1233d_9mn_58t_hF_ATmDUddHxkIZdozGwkhkIA4DavSZkl8K7M2ms3VJHnPx28/s1600/esProc_simplifies_sql_column_data_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0vnono2qS90OK30hrXDaq_zKnjyXUzbgm8Y2usTVVrEgE69vb1LM-0iORsstbqvpr7vX3DJK42qAU1233d_9mn_58t_hF_ATmDUddHxkIZdozGwkhkIA4DavSZkl8K7M2ms3VJHnPx28/s1600/esProc_simplifies_sql_column_data_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A2:<span style="color: blue;">=create(value,type)</span> aims to create an empty table sequence A2 having two fields: value and type.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A3-C4:Traverse the data in A1 and insert BID and CopyID into A2. Detailed steps: If BID of the current record is changed (what the code in B3 represents), insert a branch store record into A2 (what the code in C3 represents); modify BID of the current record to B2 (what the code in B4 represents) in order to see if BID will change in the next record; insert a DVD copy record (what the code in C4 represents).</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><span style="color: blue;">for A1</span> in the code in A3 represents traversing by loop during which one record will be fetched from A1 each time. The current record, like <span style="color: blue;">A3.BID</span>, can be accessed by the variable A3 in the loop body. The working scope of a loop statement can be represented directly by the indentation of cells, such as the working scope of A3 is B3-C4.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">After the traversing by loop is over, the final computed result will be stored in A2, as shown in the following figure:</span></div>
<div style="color: #3e3e3e;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvgK04ZqsmWmyumNLqqje2pn0itRkGz9fiUMmcexYg5hLjt1PrIrUVmjLVpkcIiZz9O9KK__wmey1wU_8fGtRN3GLS_DFJKkqeNH9skON_bq_1e2WhMX2oa3WiH7BXbRfTPuYxdW0ruk4/s1600/esProc_simplifies_sql_column_data_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvgK04ZqsmWmyumNLqqje2pn0itRkGz9fiUMmcexYg5hLjt1PrIrUVmjLVpkcIiZz9O9KK__wmey1wU_8fGtRN3GLS_DFJKkqeNH9skON_bq_1e2WhMX2oa3WiH7BXbRfTPuYxdW0ruk4/s1600/esProc_simplifies_sql_column_data_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;">Further discussion: Move more layers of data into one column</span></strong></div>
<div style="color: #3e3e3e;">
<strong><span style="font-family: inherit;"><br /></span></strong></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">In the previous example, there are only two layers of data: BID and CopyID. Actually BID, DVDID and CopyID can form three-layer data. In a similar way, we can also combine the three-layer data into one column in esProc. The code is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYBCrtDitFD-ase3LgbYW2NFwtsLAoFfGGKRf4a08IjrQY3bc-Q_HiGzznCZ7JR87027OYUsH7Kal74TPnIN9ydG31yDIm-zCveYFgK0ZyAfrzMpTU4HDqPNNfvw66eLZmjpUqp-91Zfw/s1600/esProc_simplifies_sql_column_data_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYBCrtDitFD-ase3LgbYW2NFwtsLAoFfGGKRf4a08IjrQY3bc-Q_HiGzznCZ7JR87027OYUsH7Kal74TPnIN9ydG31yDIm-zCveYFgK0ZyAfrzMpTU4HDqPNNfvw66eLZmjpUqp-91Zfw/s1600/esProc_simplifies_sql_column_data_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">Computed result is as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuPEJkhSr9SJNLZQRKUGFuNOVaHYz-hRM8ygdp6uSQVylCXO1KNHcxm2Y3kzXQkuutSGc0y-9JTLUnbm0LauyI_-qj8D8IzEN7h4S2MsmgPhnwEgGfwZ-BpYJ2F7rDUrYgLIcgW_JR0jc/s1600/esProc_simplifies_sql_column_data_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuPEJkhSr9SJNLZQRKUGFuNOVaHYz-hRM8ygdp6uSQVylCXO1KNHcxm2Y3kzXQkuutSGc0y-9JTLUnbm0LauyI_-qj8D8IzEN7h4S2MsmgPhnwEgGfwZ-BpYJ2F7rDUrYgLIcgW_JR0jc/s1600/esProc_simplifies_sql_column_data_8.jpg" /></span></a></div>
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">In addition, esProc can be called by the reporting tool or a Java program. The method is similar to that with which a Java program calls an ordinary database. The JDBC provided by esProc can be used to return a computed result of the form of ResultSet to Java main program. For more details, please refer to the related documents .</span></span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-65249663308382641052015-08-19T02:24:00.000-05:002015-08-19T02:24:00.170-05:00esProc Assists Report Development – Realization of group_concat<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">Quite a few unconventional statistical computations are difficult to handle with the reporting tools, like Jasper or BIRT, alone or in SQL. For example, to achieve an effect in a report similar to that of the <i>group_concat</i> function based on MS SQL/Oracle.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">Having a powerful, integration-friendly computational engine for structured data computing, esProc can assist the reporting tool to make the realization of the same effect more conveniently. The following example will show you how to realize <i>group_concat</i>function in esProc.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><i style="color: #333333; line-height: 18.2000007629395px;"><span lang="EN-US">Table1</span></i><span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"> in MSSQL has four fields, in which Col1, Col2 and Col3 are group fields and Col4 is summary field. Some of the data are as follows:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNQ2pSytABfMNhENQxVz8lVQwa2yJYFWb5Bl99dE80ZUgRgT-DexeISP9KXbdEzFW5HSSjK-DmgOXGAZ7hrsmjSv4L4GrUF-hyWipub_sXDGk5elRlC6Uq6r3k44FrUoKwVc54RN5oMCc/s1600/esProc_reporting_group_concat_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNQ2pSytABfMNhENQxVz8lVQwa2yJYFWb5Bl99dE80ZUgRgT-DexeISP9KXbdEzFW5HSSjK-DmgOXGAZ7hrsmjSv4L4GrUF-hyWipub_sXDGk5elRlC6Uq6r3k44FrUoKwVc54RN5oMCc/s1600/esProc_reporting_group_concat_1.jpg" /></span></a></div>
<span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><br /></span></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">The source data the reporting tool needs are as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaZjinNorg5BAozVncG8GCuOcsyJESSBTSaMT0dsQ82UA6Z1fKdRi4CecP0M4aUzhZw3qa5KrxoXoDezXvKloZ4ywLaeouJhfFBcSsWOlDBm8jKI7_VkoxCKzw1iWvZqLwHMLxweSyrZY/s1600/esProc_reporting_group_concat_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaZjinNorg5BAozVncG8GCuOcsyJESSBTSaMT0dsQ82UA6Z1fKdRi4CecP0M4aUzhZw3qa5KrxoXoDezXvKloZ4ywLaeouJhfFBcSsWOlDBm8jKI7_VkoxCKzw1iWvZqLwHMLxweSyrZY/s1600/esProc_reporting_group_concat_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">esProc script for doing this:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijnoySO2F7PgyBUVw8cz5kpPFgx1s0AOqxbB_d958QOsx44RetLBLydoX-FKHgsmyhTmgDQKuqAYkZhVyM5I2ZWc2FO1hbxQgXAAr0XQzi6OuE83xO3xbJYDodcFUtoWqkq1yycxWbQAU/s1600/esProc_reporting_group_concat_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijnoySO2F7PgyBUVw8cz5kpPFgx1s0AOqxbB_d958QOsx44RetLBLydoX-FKHgsmyhTmgDQKuqAYkZhVyM5I2ZWc2FO1hbxQgXAAr0XQzi6OuE83xO3xbJYDodcFUtoWqkq1yycxWbQAU/s1600/esProc_reporting_group_concat_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US" style="color: #002060;"><span style="font-family: inherit;">A1=mssqlDB.query("select * from table1 where Col1 in"+arg)<o:p></o:p></span></span></div>
<span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><br /></span></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">This line of code retrieves data from MSSQL by executing the SQL statement. </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">arg</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> is a parameter passed from the reporting tool, such as </span><span style="background-color: white; color: #002060; line-height: 18.2000007629395px;">(10,20)</span><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">.</span><span style="background-color: white; color: #002060; line-height: 18.2000007629395px;"> </span><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">The result is as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL_28N_MvwOKORlWUmd9g1F7sm2DcYteIHKHFFtFF1Y-MxYWRTHHpXQNucSD8vPak2SfdXFzLdLsTs_g4k-Uh7IG1DFIG9PpcMO04Ip9CoIMSGG23tKfMQhyphenhyphenJAoZnS8K5HKHN7RcHsoCU/s1600/esProc_reporting_group_concat_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" height="122" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL_28N_MvwOKORlWUmd9g1F7sm2DcYteIHKHFFtFF1Y-MxYWRTHHpXQNucSD8vPak2SfdXFzLdLsTs_g4k-Uh7IG1DFIG9PpcMO04Ip9CoIMSGG23tKfMQhyphenhyphenJAoZnS8K5HKHN7RcHsoCU/s320/esProc_reporting_group_concat_4.jpg" width="320" /></span></a></div>
<span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><br /></span></span>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><span lang="EN-US" style="color: #002060;">A2=A1.group(Col1,Col2,Col3;~.(Col4).string@d():Col4)</span><span lang="EN-US"><o:p></o:p></span></span></div>
<span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"><span style="background-color: white; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><br /></span></span></span>
<span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><span style="background-color: white; line-height: 18.2000007629395px;">This line of code groups data by Col1, Col2 and Col3 and concatenates the strings in Col4 together by commas. ~ represents each group of data</span><a href="https://www.blogger.com/null" name="_GoBack" style="background-color: white; color: #015782; line-height: 18.2000007629395px; text-decoration: none;"></a><span style="background-color: white; line-height: 18.2000007629395px;">. The first group, for instance, has three records. ~.(Col4) means retrieving Col4 field from each group. It is the set [A12G3 , K78DE , MAT12] for the first group. </span><i style="background-color: white; line-height: 18.2000007629395px;">string</i><span style="background-color: white; line-height: 18.2000007629395px;"> function concatenates members of a set into a string, delimited by commas by default. </span><i style="background-color: white; line-height: 18.2000007629395px;">@d</i><span style="background-color: white; line-height: 18.2000007629395px;"> option forbids surrounding members of the set with quotation marks. Thus expression </span><span style="background-color: white; color: #002060; line-height: 18.2000007629395px;">[A12G3 , K78DE , MAT12].string@d() </span><span style="background-color: white; line-height: 18.2000007629395px;">is equivalent to “A12G3 , K78DE , MAT12”. Expression “:Col4” means renaming the result of computing the previous expression as Col4.</span></span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzNhFRMd6vyuBVplYbQrvrHo78vORhrKE1_HQj8uaNkE9PHimYmkukoVtEBRtBA_3EWhcyl0h3wqfXUJ86AZB4nPD33oebzexm9CzGgPRPIKfW2R8gdxP6vNYLHPAsZlk1NNIoT7M_nEY/s1600/esProc_reporting_group_concat_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzNhFRMd6vyuBVplYbQrvrHo78vORhrKE1_HQj8uaNkE9PHimYmkukoVtEBRtBA_3EWhcyl0h3wqfXUJ86AZB4nPD33oebzexm9CzGgPRPIKfW2R8gdxP6vNYLHPAsZlk1NNIoT7M_nEY/s1600/esProc_reporting_group_concat_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">A3 gets the final result of this example:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPJkU8fNVj1yNvq-dqDQZyFvAXpJ-oRK15sRg3xo520SYLGjvwTGXcS0FSjm2ahwThvaVGV9DGKWRWW84WY4Tk_PlrTUdZOEvEDVsrJX0vGewTWnIM3JsWmf-0klHJnZCXWT2Nhj2HPQk/s1600/esProc_reporting_group_concat_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPJkU8fNVj1yNvq-dqDQZyFvAXpJ-oRK15sRg3xo520SYLGjvwTGXcS0FSjm2ahwThvaVGV9DGKWRWW84WY4Tk_PlrTUdZOEvEDVsrJX0vGewTWnIM3JsWmf-0klHJnZCXWT2Nhj2HPQk/s1600/esProc_reporting_group_concat_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">A3: <span style="color: #002060;">result A2</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">This line of code returns the result of A2 to the reporting tool.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">esProc provides the JDBC interface to be integrated with the reporting tool, which will recognize esProc as a database. Please refer to related documents for the integration solution.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">Now let’s design the report based on, for instance, JasperReport. The appearance and layout is as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8DtUQhQK6Cjsi7J5X2wyvat49XeeH8_ax6I3uY-KPCgpzQVdpgUv-eNWBZT9ePhrAJMazz3fEMIC2lR-02_ybB_fFp3S0D0_U8SI6qz0itSNPg-W-vunS0qI5bhP6VGKZXpo4KXduIe4/s1600/esProc_reporting_group_concat_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8DtUQhQK6Cjsi7J5X2wyvat49XeeH8_ax6I3uY-KPCgpzQVdpgUv-eNWBZT9ePhrAJMazz3fEMIC2lR-02_ybB_fFp3S0D0_U8SI6qz0itSNPg-W-vunS0qI5bhP6VGKZXpo4KXduIe4/s1600/esProc_reporting_group_concat_7.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px; text-indent: 28px;">Click on Preview to see the result report:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpf3uDErwWooOIx0kdtQPfclAcfawRy2R3Xw3s-R0fu7xsjMOTMVIP5wmPL1eTUxzCnfg0pj_5VOUuUtm8z0Nw4z_BvW3AgfyD3oYNFnZa35Ez8pNq6rEzWMyDh3xpFmV504DEBTs_JDg/s1600/esProc_reporting_group_concat_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpf3uDErwWooOIx0kdtQPfclAcfawRy2R3Xw3s-R0fu7xsjMOTMVIP5wmPL1eTUxzCnfg0pj_5VOUuUtm8z0Nw4z_BvW3AgfyD3oYNFnZa35Ez8pNq6rEzWMyDh3xpFmV504DEBTs_JDg/s1600/esProc_reporting_group_concat_8.jpg" /></span></a></div>
<span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"><span style="background-color: white; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><br /></span></span></span>
<span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;"><span style="background-color: white; line-height: 18.2000007629395px;">The way the reporting tool calls the esProc script is the same as that it calls the stored procedure. Save the esProc script in this example as </span><i style="background-color: white; line-height: 18.2000007629395px;">group_concat.dfx, </i><span style="background-color: white; line-height: 18.2000007629395px;">and it can be called by </span><span style="background-color: white; color: #002060; line-height: 18.2000007629395px;">group_concat $P{arg} </span><span style="background-color: white; line-height: 18.2000007629395px;">in JasperReport’s SQL designer. </span></span></span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-76186481429293550412015-08-18T01:13:00.004-05:002015-08-18T01:13:49.457-05:00esProc Assists Report Development – Dynamic Datasources<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">Reporting tools, such as Jasper Report and BIRT, don’t have enough support for multi-<a href="https://www.blogger.com/null" name="_GoBack" style="color: #015782; text-decoration: none;"></a>datasources, leading to complicated Java program for realizing dynamic datasources. But by using esProc to assist the reporting tool, this won’t be a problem anymore. The following example will teach you how esProc works to realize the dynamic datasources.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><i><span lang="EN-US">myDB1</span></i><span lang="EN-US"> and <i>myDB2</i> are different databases, but both have a table <i>sales</i> holding different data. We want to control the source of data of the report through the parameter <i>PsCode</i> and the range of data retrieval through the other two parameters – <i>Pbegin</i> and<i>Pend</i>.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"><span style="font-family: inherit;">esProc code for doing this:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx8SoZCHc5Lq1nA39drjxqDabWTMgsalA00R97yh16T2gzRV-31vfsz11tDI8OxKS-B0BrF13TI0Gdfi1tMaFtnZz9WLlPLd5blL6ZowOhgeWVNuAUO4bT3bnet4yoczOKbIllfPFYNZ4/s1600/esProc_report_dynamic_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx8SoZCHc5Lq1nA39drjxqDabWTMgsalA00R97yh16T2gzRV-31vfsz11tDI8OxKS-B0BrF13TI0Gdfi1tMaFtnZz9WLlPLd5blL6ZowOhgeWVNuAUO4bT3bnet4yoczOKbIllfPFYNZ4/s1600/esProc_report_dynamic_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div align="left" class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">As you can see, esProc just uses a line of code to achieve using datasources dynamically.<o:p></o:p></span></span></div>
<i style="background-color: white; color: #333333; line-height: 18.2000007629395px;"><span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></i><span style="font-family: inherit;"><i style="color: #333333; line-height: 18.2000007629395px;"><span lang="EN-US">sCode</span></i><span lang="EN-US" style="color: #333333; line-height: 18.2000007629395px;">, <i>begin</i> and <i>end</i> are all esProc parameters. They can be set in the following window:</span><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> </span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKi9Wtt46Z2RyS0WF9nN7oKL5xQQS_kod7hQFS4ybb1g7U_TprGOnZAyqwzb9-51KW7euVmdMRDLoo7DGClzdwy7TBWlctOHPHj2nn8bZI24CVd9xkcKBbIcD56rdasR7_v7uhRcW8VJE/s1600/esProc_report_dynamic_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKi9Wtt46Z2RyS0WF9nN7oKL5xQQS_kod7hQFS4ybb1g7U_TprGOnZAyqwzb9-51KW7euVmdMRDLoo7DGClzdwy7TBWlctOHPHj2nn8bZI24CVd9xkcKBbIcD56rdasR7_v7uhRcW8VJE/s1600/esProc_report_dynamic_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div align="left" class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><i><span lang="EN-US">begin</span></i><span lang="EN-US"> and <i>end</i> are used to define the range of retrieving data from SQL and <i>sCode</i> is used to switch between datasources . The macro ${sCode} is to parse the parameters to get an esProc expression. To assign myDB2 to sCode, for instance, the above esProc script will be parsed into <span style="color: #002060;">result myDB2.query("select * from sales where OrderDate>=? and OrderDate <=?",begin,end)</span>.<o:p></o:p></span></span></div>
<div align="left" class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<div align="left" class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><i><span lang="EN-US">query</span></i><span lang="EN-US"> function is used to execute an SQL statement, and receives parameters passed to it.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<i><span lang="EN-US"><span style="font-family: inherit;"><br /></span></span></i></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><i><span lang="EN-US">result</span></i><span lang="EN-US"> statement will return the result to the reporting tool.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span lang="EN-US"><span style="font-family: inherit;">esProc provides JDBC interface to be integrated with the reporting tool, which will identify esProc as a database. For detailed integration solution, please refer to related documents<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">Next let’s take Jasper Report as an example to design a report. Its appearance and layout is as follows:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgahioswxtJ3oCare7ttpsfAQ42r6T9iu1cf_6QdZbvs8eMrtxNqz4Wsr9Xwzl0BXPLao9NXckpPnwWKZ-oi1gGux77LAfTsc3ApdBAJFPji3NAzE85TC7RPzcb4Hd8ssLeP3Nh1Xj57NY/s1600/esProc_report_dynamic_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgahioswxtJ3oCare7ttpsfAQ42r6T9iu1cf_6QdZbvs8eMrtxNqz4Wsr9Xwzl0BXPLao9NXckpPnwWKZ-oi1gGux77LAfTsc3ApdBAJFPji3NAzE85TC7RPzcb4Hd8ssLeP3Nh1Xj57NY/s1600/esProc_report_dynamic_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">Define three parameters – </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">PsCode</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">, </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">Pbegin</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> and </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">Pend</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> – in the report to correspond to the three esProc parameters. Click on Preview to see the completed report:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRl-_vp8HIbbeLNk1X4nDI93yrlyqEKbQEYD9JZhM7-Q4_uQi-jv-WqZ0WXQ3lLx-ERgslWwi6si-CJHOUXHAq0V3qJYvJlVf9zmYuS4s7sdS0TVf3jXE8BRw3f8iUZhvx-7CRXSRHYkU/s1600/esProc_report_dynamic_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRl-_vp8HIbbeLNk1X4nDI93yrlyqEKbQEYD9JZhM7-Q4_uQi-jv-WqZ0WXQ3lLx-ERgslWwi6si-CJHOUXHAq0V3qJYvJlVf9zmYuS4s7sdS0TVf3jXE8BRw3f8iUZhvx-7CRXSRHYkU/s1600/esProc_report_dynamic_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">In the above report, PsCode’s value is </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">myDB1</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">. We can change the value to </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">myDB2</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> to see the effect of having dynamic datasources: </span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHJlS9gW7pfZP42VQUZjkbo-nTV2rz88mgAmvJ6ZbQNgYjeBxB0iEbVsaKO3QsaUUkkjjl8kDB8MwxmNs4-5Z0LnM8zfVCNkcp08n1VUXvDRIAvcgZhkb335m3HDBIQuteOPrSrSI1AFo/s1600/esProc_report_dynamic_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHJlS9gW7pfZP42VQUZjkbo-nTV2rz88mgAmvJ6ZbQNgYjeBxB0iEbVsaKO3QsaUUkkjjl8kDB8MwxmNs4-5Z0LnM8zfVCNkcp08n1VUXvDRIAvcgZhkb335m3HDBIQuteOPrSrSI1AFo/s1600/esProc_report_dynamic_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px;">
<span style="font-family: inherit;"><span lang="EN-US">Notice that the way a report calls the esProc script is the same as that it calls the stored procedure. If we save the script as<i>dsource.dfx</i>, then it can be called by </span><span lang="EN-US" style="color: #002060;">dsource $P{PsCode},$P{Pbegin},$P{Pend} </span><span lang="EN-US">in Jasper Report’s SQL designer.<span style="color: #002060;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal" style="background-color: white; color: #333333; line-height: 18.2000007629395px; text-indent: 21pt;">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">That the datasource name is directly used as the parameter, as in the first esProc script, may cause security problem. Sometimes users prefer to use numbers to represent the datasources. For instance, if PsCode’s value is 1, then retrieve data from myDB1; if the parameter has anotehr value, retrieve data from myDB2. This can be realized with the following code:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioT_JJNRq02LcYzTmcL5gp-iNIRGBmI-SVCTkIsu3Sgy1dLgknY011X2TZvnEA-LSuNAcNXYU64ekUTJ4ZRY7GHFpVjITKBhbRB8hCOjzv3cJWf8ZWyJo06xWzLguFUoLOo8ObAVmLFDk/s1600/esProc_report_dynamic_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioT_JJNRq02LcYzTmcL5gp-iNIRGBmI-SVCTkIsu3Sgy1dLgknY011X2TZvnEA-LSuNAcNXYU64ekUTJ4ZRY7GHFpVjITKBhbRB8hCOjzv3cJWf8ZWyJo06xWzLguFUoLOo8ObAVmLFDk/s1600/esProc_report_dynamic_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;">This esProc script uses </span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;">connect</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> and</span><i style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> close</i><span style="background-color: white; color: #333333; line-height: 18.2000007629395px;"> function to connect to or close the database explicitly, which features a higher flexibility.</span></span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0tag:blogger.com,1999:blog-105541460155470780.post-74954726895354020622015-08-17T00:47:00.013-05:002015-08-17T00:47:52.495-05:00esProc Assists Report Development – JOIN Operation in MongoDB<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Heterogeneous datasources are frequently needed in report development, but they are difficult to realize using the reporting tool, like JasperReport, alone. To present the result of joining two MongoDB collections together, for instance. Though JasperReport has the functions of virtual data source or table join, but they are offered only in the commercial or higher versions and probably won’t appear in free version. Moreover, these two functions support connection to only two datasources. If users need more, the program development becomes complicated. Additionally, they don’t support subsequent structured data computing of the joined data as SQL does, due to providing only a graphical interface.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">esProc has a powerful structured data computing engine, supports heterogeneous datasources and is easy to be integrated, thus it is useful for assisting the reporting tool to realize MongoDB join conveniently. The following example will show you how esProc works to create a join in MongoDB.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">There are two collections – <em>sales</em> and <em>emp</em> – in MongoDB. Logically, <em>sale</em>’s SellerId field is equivalent to a foreign key that points to <em>emp</em>’s EId field. The task is to query orders in <em>sales</em> by the time range, create a left join with <em>emp</em> and present the result in the report. Some of the source data are as follows:</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Collection <em>sales</em></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjopYZJ7jzGHSI_CTF_08AzUnOS6CP9z1NLUEcTzNz-zRGOdUM0kr7QxHaKaoDY35-enT-upbTRtasGcSvSsnCp0GuShHbltctkXpeMu-9e3dZQ1i1qJ34uoEB3klc6pq7qhC7blrwA200/s1600/esProc_report_mongodb_join_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjopYZJ7jzGHSI_CTF_08AzUnOS6CP9z1NLUEcTzNz-zRGOdUM0kr7QxHaKaoDY35-enT-upbTRtasGcSvSsnCp0GuShHbltctkXpeMu-9e3dZQ1i1qJ34uoEB3klc6pq7qhC7blrwA200/s1600/esProc_report_mongodb_join_1.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">Collection emp</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKK2J2T8Yafi4umzFat32tmZu35Nk6uNXHMYLIwE7nXPzgS_6gX26-Pp8COpIdtcfbSOrZzpQVYaFa_YW3UPFQP12eerUqtkBzDRox1e_rOlgQf0-dB1Oj2CoMafoJRvNI3o2deWrEv_s/s1600/esProc_report_mongodb_join_2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKK2J2T8Yafi4umzFat32tmZu35Nk6uNXHMYLIwE7nXPzgS_6gX26-Pp8COpIdtcfbSOrZzpQVYaFa_YW3UPFQP12eerUqtkBzDRox1e_rOlgQf0-dB1Oj2CoMafoJRvNI3o2deWrEv_s/s1600/esProc_report_mongodb_join_2.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><span style="color: #3e3e3e;">esProc script for completing the task:</span> </span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDGgvpbtp4DElNnP9GGGm4xeu-I78lW9zqm-G2GD1lZxFAYyCietVdlrW3P5P_MdPXps_EQKV1Wu9UV2cbhOC6Ud7R0io9CjEw6S71cSpMnHhjR0H8RLTwkQ4EaurgGkzgMwjdxxXTKN0/s1600/esProc_report_mongodb_join_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDGgvpbtp4DElNnP9GGGm4xeu-I78lW9zqm-G2GD1lZxFAYyCietVdlrW3P5P_MdPXps_EQKV1Wu9UV2cbhOC6Ud7R0io9CjEw6S71cSpMnHhjR0H8RLTwkQ4EaurgGkzgMwjdxxXTKN0/s1600/esProc_report_mongodb_join_3.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A1=MongoDB(“mongo://localhost:27017/test?user=root&password=sa”)</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code establishes the connection to MongoDB. User name and password can be specified through the two parameters <em>user</em> and <em>password</em>.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">As connecting to an ordinary database, esProc also supports connecting to MongoDB through JDBC. But since the third-party JDBC is not free, and has a weaker function than the official library function – for example, it cannot retrieve the multilayer data, esProc will directly encapsulate the native methods, thereby retaining the function and syntax of MongoDB. <em>find </em>function, for example, can be used in this case.</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A2=A1.find(“sales”,”{‘$and’:[{'OrderDate':{'$gte':'"+string(begin)+"'}},{'OrderDate':{'$lte':'"+string(end)+"'}}]}”,”{_id:0}”).fetch()</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code finds records during a certain time period from MongoDB’s collection <em>sales</em>. <em>find</em> function’s first parameter is the collection’s name, its second parameter is the query condition that is defined according to MongoDB syntax and the third one specifies the field to be returned. Note that <em>begin</em> and <em>end</em> in the query condition are external parameters passed from the report, respectively representing the beginning date and the ending date of OrderDate.</span></div>
<div style="color: #3e3e3e;">
<em><span style="font-family: inherit;"><br /></span></em></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><em>find</em> function will return a cursor, which means it doesn’t retrieve data into the memory entirely and thus supports processing big data. Data of the result cursor can be further processed with functions like <em>skip</em>, <em>sort</em> and <em>conj</em> and data retrieval won’t start until either <em>fetch</em> function or <em>groups</em> function, or <em>for</em> statement appears. <em>fetch()</em> function is used in this example to fetch the data into the memory. </span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Suppose the time period is from 2009-01-01 to 2009-12-31, result of A2 is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy8-l6SxIrg9GcG5onSs6xzJDYDhopSSszmduuDtOrSAMFq6l9u7Y5RqRA1qOl8uCz4X2wVJ7Of_WafkIJCfJFyXOXruDEQXglOzVs6wLp38d1d99H9whS4uZa-93FWEwsYY1BywPbQpw/s1600/esProc_report_mongodb_join_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy8-l6SxIrg9GcG5onSs6xzJDYDhopSSszmduuDtOrSAMFq6l9u7Y5RqRA1qOl8uCz4X2wVJ7Of_WafkIJCfJFyXOXruDEQXglOzVs6wLp38d1d99H9whS4uZa-93FWEwsYY1BywPbQpw/s1600/esProc_report_mongodb_join_4.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A3=A1.find(“emp”,,”{_id:0}”).fetch()</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code retrieves all data, except for <em>_id</em> field, from collection <em>emp</em> unconditionally. Result is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLcqVrnL6WHxYSt2Mg1-3Y7Y-VWs_jv6VJPniIAYeaaxxkdLcvXeY8xiBCNXFTI1PaZTeZA2SFQ33766KN3YeUMrgcvqJICBpZF-NQBI0N9NF0ROG718l_0aMIuSxOAj5So1AWupGlzLc/s1600/esProc_report_mongodb_join_5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLcqVrnL6WHxYSt2Mg1-3Y7Y-VWs_jv6VJPniIAYeaaxxkdLcvXeY8xiBCNXFTI1PaZTeZA2SFQ33766KN3YeUMrgcvqJICBpZF-NQBI0N9NF0ROG718l_0aMIuSxOAj5So1AWupGlzLc/s1600/esProc_report_mongodb_join_5.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A4=A1.close()</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code closes the connection to MongoDB established in A1.</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A5=join@1(A2:sales,SellerId;A3:emp,EId)</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">This line of code creates a left join between A2 and A3. The fields to join them together are A2’s SellerId and A3’s EId. Intuitively, two parts of the joined data are respectively named <em>sales</em> and<em> emp</em>. <em>join</em> function is used to perform the <em>join</em> operation, in which <em>@1 </em>option means left join. The result can be seen in the left part of the following figure:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi6vDtzg0yQa39Y1kYTptyT5b16Puql3EzmO-DZXEyWeq8EoPuci2VakNsGzspy4GjxtqMlxLeD19n-4CCE25EpQPpGfT5e3HcaOfyt9RlpQOrPk7feKzESFvDJAUPsdmJXc6oo7xFO1I/s1600/esProc_report_mongodb_join_6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi6vDtzg0yQa39Y1kYTptyT5b16Puql3EzmO-DZXEyWeq8EoPuci2VakNsGzspy4GjxtqMlxLeD19n-4CCE25EpQPpGfT5e3HcaOfyt9RlpQOrPk7feKzESFvDJAUPsdmJXc6oo7xFO1I/s1600/esProc_report_mongodb_join_6.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">It can be seen that some of the SellerId in <em>sales</em> cannot find corresponding records in <em>emp</em> because of the left join. We can use <em>@f</em> to perform a full join; without any option, the function will perform an inner join.</span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;"><br /></span></span></div>
<div style="color: #3e3e3e;">
<span style="color: blue;"><span style="font-family: inherit;">A6=A5.new(sales.OrderID:OrderID,sales.Client:Client,sales.Amount:Amount,sales.OrderDate:OrderDate,emp.Name:Name,emp.Dept:Dept,emp.Gender:Gender)</span></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">A5 joins the data together. A6 gets the fields we want from the result of joining and creates a two-dimensional table using <em>new</em> function. For example, <span style="color: blue;">sales.OrderID:OrderID</span> means getting sales.OrderID field from A5 and rename it OrderID (because reporting tools cannot identify field names like sales.OrderID). Result is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFWyVIujd8ADblFPnZS-i7rFNEanpaD3yH1yC61Rmf5m__huMvuNYh5Y42Vil6ljNvhA8QeVDi0lSxrlZGy5Me3ur2sSLOuU4XFnXfVex2keljd5sLjehkEy7uxN0cqQlZHOtZRou8eQ4/s1600/esProc_report_mongodb_join_7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFWyVIujd8ADblFPnZS-i7rFNEanpaD3yH1yC61Rmf5m__huMvuNYh5Y42Vil6ljNvhA8QeVDi0lSxrlZGy5Me3ur2sSLOuU4XFnXfVex2keljd5sLjehkEy7uxN0cqQlZHOtZRou8eQ4/s1600/esProc_report_mongodb_join_7.jpg" /></span></a></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Now all data are ready for creating the report. The final step is to return A6’s two-dimensional table to the reporting tool with<span style="color: blue;"> result A6</span>. esProc offers JDBC interface to be integrated with the reporting tool, and the latter will identify it as the ordinary database. Please refer to related documents for the integration solution.</span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;"><br /></span></div>
<div style="color: #3e3e3e;">
<span style="font-family: inherit;">Then design the report using JasperReport, for instance. The appearance and layout is as follows:</span></div>
<span style="font-family: inherit;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN5DqL2ioptRdCWRRWV1EmZgjGldB1JczXUVQbNHLeigIsokG7iLY7YFWjap_SqAwKjLDNx2SnKzF0FYEVC0s9BonsQrpwhQGa-aMUNO_CESTirb7XHWWTDIItUirgkSl5ZQcjJg_IFSM/s1600/esProc_report_mongodb_join_8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN5DqL2ioptRdCWRRWV1EmZgjGldB1JczXUVQbNHLeigIsokG7iLY7YFWjap_SqAwKjLDNx2SnKzF0FYEVC0s9BonsQrpwhQGa-aMUNO_CESTirb7XHWWTDIItUirgkSl5ZQcjJg_IFSM/s1600/esProc_report_mongodb_join_8.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">Define two parameters – Pbegin and Pend – in the report according to the corresponding esProc parameters. Click Preview to see the report:</span></span><br />
<span style="color: #3e3e3e;"><span style="font-family: inherit;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnyS2K2T19EQYyyAjABSwAM9kiNTiy8rJ85u5_XcZPQOqf5WV59Dce0vTE2im5iNY24i5sFHFaMiC4mzRHvKVnGGepj3n217RHa0jPOthyphenhyphenZ5syUyj1FbHH-zS2rbUMEb8VBig67OuXgRQ/s1600/esProc_report_mongodb_join_9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnyS2K2T19EQYyyAjABSwAM9kiNTiy8rJ85u5_XcZPQOqf5WV59Dce0vTE2im5iNY24i5sFHFaMiC4mzRHvKVnGGepj3n217RHa0jPOthyphenhyphenZ5syUyj1FbHH-zS2rbUMEb8VBig67OuXgRQ/s1600/esProc_report_mongodb_join_9.jpg" /></span></a></div>
<span style="font-family: inherit;"><br /></span>
<span style="color: #3e3e3e;"><span style="font-family: inherit;">The way the reporting tool calls the esProc script is the same as that it calls the stored procedure. Save the esProc script as, say, mongodbJoin.dfx to be called by mongodbJoin $P{pbegin},$P{pend} in JasperReport’s SQL designer. </span></span>Anonymoushttp://www.blogger.com/profile/10194258362281666656noreply@blogger.com0