02 May 2008

Grouping by week through SQL

SELECT   TRUNC (poh_date, 'IW') weeks,

         COUNT (TO_CHAR (poh_date, 'IW')) RECORDS

    FROM poh_policy_history

   WHERE poh_date BETWEEN TO_DATE ('01/01/2007', 'dd/mm/yyyy')

                      AND TO_DATE ('31/12/2007', 'dd/mm/yyyy')

GROUP BY TRUNC (poh_date, 'IW')

select count(*) from poh_policy_history where poh_date between  to_date('08/01/2007','dd/mm/yyyy') and to_date('14/01/2007','dd/mm/yyyy')