Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Forked from nagoodman/gist:1563401
Created January 5, 2012 03:45
Show Gist options
  • Select an option

  • Save thinkjson/1563609 to your computer and use it in GitHub Desktop.

Select an option

Save thinkjson/1563609 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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment