DB2 - Select values based on number of days in current month -
i have table below.
table name (issues):
id issue_id created_date 1 101 15 july 2016 2 102 13 july 2016 3 103 10 july 2016 4 104 8 july 2016 5 103 7 july 2016 6 104 19 june 2016 7 103 10 june 2016 8 104 1 june 2016
i want retrieve number of issues(count) opened in last 30/31/28 days based on number of days in current month.
for example, in month of july, have 31 days, want retrieve issues got opened in last 31 days.
if in case of june, have 30 days, have retrieve issues opened in last 30 days.
in db2, number of days on month can retrieved
day(last_day(date(current timestamp)))
i still confused how apply query. have limited knowledge on queries.
thanks in advance.
the following query didn't work.
select count(*) issues month(created_date) > (month( date(current timestamp) ) - 1 month) , day(date (created_date)) > day(date(current timestamp))
you can substitute in value number of days.
basic in time select
select * sometable somedate > current date - 31 days
back in time select using function number of days.
select * sometable somedate > current date - day(last_day(date(current timestamp))) days
but of select month month
select * sometable somedate > current date - 1 months
note: place i've found n days useful pulling out stuff weekend on monday or holidays.
Comments
Post a Comment