postgresql - SQL query between current date and previous week -


select sge_job.j_owner "owner"       ,sum(sge_job_usage.ju_cpu) "cpu total" sge_job_usage, sge_job  group j_owner; 

here current sql query reads in cpu% , job owner i'm having trouble incorporating sum above if it's between current date 14days(2 weeks) ago.

in sge_job_usage table belongs both:

ju_start_time, ju_end_time

anyone me towards how can check if it's between current date - 14 days before , checks end_time date see if still going then?

answer outputs need below:

select sge_job.j_owner "owner"        ,sum(sge_job_usage.ju_cpu) "cpu total"  sge_job_usage, sge_job   ju_start_time between localtimestamp - interval '1 week' , localtimestamp  group j_owner; 

adc syntax not valid postgresql.

i don't understand condition want applied ju_end_date. should similar 1 on ju_start_time.

select sge_job.j_owner "owner"       ,sum(sge_job_usage.ju_cpu) "cpu total" sge_job_usage, sge_job  sge_job_usage.c1 = sge_job.c2   , ju_start_time between localtimestamp - interval '14 days' , localtimestamp group j_owner; 

i don't have test environment can't test think should work.

for more information on subject check

http://www.postgresql.org/docs/9.1/static/functions-datetime.html

edit: ypercube said, need join condition on 2 tables.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -