Skip to content

Instantly share code, notes, and snippets.

@nagoodman
Created January 5, 2012 02:28
Show Gist options
  • Save nagoodman/1563401 to your computer and use it in GitHub Desktop.
Save nagoodman/1563401 to your computer and use it in GitHub Desktop.
sample sql luciddb
select 'Last 30 Days', sum(measure1)
from time t, fact f
where f.timeid = t.timeid
and
f.date between applib.add_days(current_date, -30) and current_date
UNION ALL
select 'Current Month', sum(measure1)
from time t, fact f
where f.timeid = t.timeid
and t.month = applib.extract_timestamp(current_timestamp, 'MONTH')+1
and t.year = applib.extract_timestamp(current_timestamp, 'YEAR')
UNION ALL
select 'Previous Month', sum(measure1)
from time t, fact f
where f.timeid = t.timeid
and t.month = applib.extract_timestamp( (current_timestamp - INTERVAL '1' month), 'MONTH')+1
and t.year = applib.extract_timestamp( (current_timestamp - INTERVAL '1' month), 'YEAR')
@Jach
Copy link

Jach commented Jan 5, 2012

Alternate where clause for current month for fun:

where f.timeid = t.timeid
and t.year = cast(applib.execute_function('js', 'function execute() { return new Date().getFullYear() }') as integer)
and t.month = cast(applib.execute_function('js', 'function execute() { return new Date().getMonth() + 1 }') as integer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment