Judy

Posted on

# Calculate the Average Interval of Projects for Each User #eg17

Problem description & analysis

We have a table PROJECTS in the database. Below is a part of the table:

UID contains user IDs. PD contains project creation date. We are trying to calculate the average interval (month) of different projects for each user. Below is part of the desired result:

Solution

Write the following script p1.dfx in esProc:

Explanation:

A1   Connect to the database named demo.

A2  Return the query result as a table sequence and close database connection when code is executed. Group the table sequence by UID, and for each group calculate the month difference of each project creation date and the previous project creation date. Assign 0 to the value of the first member in each group.

A3  Define variable pm (the maximum number of projects of each user) and calculate the number.

A4  Supply 0s to A2, a sequence of sequences, according to value of pm.

A5  Transpose rows to columns on A4 and calculate the averages.

Read How to Call an SPL SCript in Java to learn about the method of integrating the SPL script with a Java program.

Q & A Collection

https://stackoverflow.com/questions/64145457/calculating-average-time-between-dates-in-sql