Since I've been writing posts, one of the things I've been struggling with is writing code straight into the blog. Did a little research and found others facing the same problem. A lot of people recommended Gist, so this is me just trying it out.
Since I'm primarily focusing on Grails and SQL these days, I'll test out some sql, groovy and gsp code. First off the SQL:
Next the GSP:
Finally some Groovy:
The verdict: FULLY AWESOME!
Since I'm primarily focusing on Grails and SQL these days, I'll test out some sql, groovy and gsp code. First off the SQL:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH C1 AS ( | |
SELECT date_created AS ts, type, | |
ROW_NUMBER() OVER( ORDER BY date_created) AS start_ordinal | |
FROM dst_audit_log where type = 'LOG_IN' | |
UNION ALL | |
SELECT date_created as endtime, type, NULL | |
FROM dst_audit_log where type = 'LOG_OUT' | |
), | |
C2 AS ( | |
SELECT *, | |
ROW_NUMBER() OVER(ORDER BY ts, type) AS start_or_end_ordinal | |
FROM C1 | |
) | |
SELECT MAX(2 * start_ordinal - start_or_end_ordinal) AS peakSessionCount, ts :: DATE as date_created | |
FROM C2 | |
WHERE type = 'LOG_IN' | |
group by ts :: DATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<g:each in="${report}"> | |
<tr> | |
<td><g:formatDate format="MMM dd, yyyy" date="${it?.date_created}"/></td> | |
<td>${it.customer_count}</td> | |
<td>${it.customer_with_spouse_count}</td> | |
</tr> | |
</g:each> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sumavg | |
if(report && report.size() > 0) { | |
sumavg = [:] | |
sumavg.customer_count = report*.customer_count.findAll { it != null }.sum() ?: 0 | |
} |