title: previous trimester in oracle SQL
body: <p>i have following sql which gives me a report of dossiers being handled by persons the last full three months but i would like to adopt it so that i get those from the previous trimester, eg when i would run it now i should get dossiers from the months 10, 11 and 12 of 2011 and in april those from 1, 2 and 3 of 2012. Can someone make a suggestion how to handle this the easiest way. Those report are stored as sql in a database so they should be be able to run anytime.</p>
  
  <pre><code>select
   pers_nr "person", 
   to_char(import_dt,'YYMM') "year and month",
   count(pers_nr) "dossiers" 
  from 
    rdms_3codon
  where
   to_char(import_dt,'YY')*12+to_char(import_dt,'MM') &gt; to_char(sysdate,'YY')*12+to_char(sysdate,'MM')-4
   and to_char(import_dt,'YY')*12+to_char(import_dt,'MM') &lt; to_char(sysdate,'YY')*12+to_char(sysdate,'MM')
  group by 
   pers_nr, 
   to_char(import_dt,'YYMM') 
  order by
   pers_nr
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Here the query enhanced with the suggestion by Joachim</p>
  
  <pre><code>select 
   pers_nr "person",  
   to_char(import_dt,'YYMM') "year and month", 
   count(pers_nr) "dossiers"  
  from  
    rdms_3codon 
  where 
   trunc(import_dt) &gt;= trunc(trunc(sysdate, 'Q') -1, 'Q')
   and trunc(import_dt) &lt; trunc(sysdate, 'Q')-1/(24*60*60)
  group by  
   pers_nr,  
   to_char(import_dt,'YYMM')  
  order by 
   pers_nr 
  </code></pre>