sql - How to SELECT number of hours worked in specifc weeks using postresql -
i'm trying find out how many hours employees worked on specific weeks in april , march.
when trying find total hours worked (numeric value), i'm given "date out of range" error. i'm sure made simple mistake in select queries. point out me what's wrong?
how make select query if wanted number of hours worked 2015-04-05 2015-04-11? if can figure out how numbers specified week, that'll me other weeks need well. pardon newbish questions, i'm still new sql little experience.
select sum(case when hours_worked between dateadd(ww,-1,'2015-04-05') , dateadd(ww,-00,'2015-04-05') r.hours_worked end) hours_worked sum(case when hours_worked between dateadd (wk,-1,'2015-3-14') , dateadd(wk,-0,'2015-3-20') r.hours_worked end) hours_worked
here's 1 way write query similar yours:
select name, sum( case when hours_worked between (to_date('2015-04-05', 'yyyy-mm-dd') - interval '7 days') , to_date('2015-04-05', 'yyyy-mm-dd') 1 else 0 end ) number_of_records test group name
to_date
function converts string date.
- interval '7 days'
tells postgresql go last week.
using hints query above, should able suit needs.
Comments
Post a Comment