Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: sql query

Re: sql query

From: Galen Boyer <galenboyer_at_hotpop.com>
Date: 18 Jun 2002 22:38:07 -0500
Message-ID: <u7kkv4vk4.fsf@hotpop.com>


> I have a table with 800Millian rows. I want to write a sql query where
> i want to find out how many rows fall between certain dates. It is
> bascially find out each quater data in year for last 6 years.
>
> Basically combining the below statments into one single sql query
>
> select count(*) from orddet where order_date >= '01-JAN-1996' and order_date
> <= '31-MAR-1996';
> select count(*) from orddet where order_date >= '01-APR-1996' and order_date
> <= '30-JUN-1996';
> select count(*) from orddet where order_date >= '01-JUL-1996' and order_date
> <= '30-SEP-1996';
> select count(*) from orddet where order_date >= '01-OCT-1996' and order_date
> <= '31-DEC-1996';
>
> select count(*) from orddet where order_date >= '01-JAN-1997' and order_date
> <= '31-MAR-1997';
> select count(*) from orddet where order_date >= '01-APR-1997' and order_date
> <= '30-JUN-1997';
> select count(*) from orddet where order_date >= '01-JUL-1997' and order_date
> <= '30-SEP-1997';
> select count(*) from orddet where order_date >= '01-OCT-1997' and order_date
> <= '31-DEC-1997';

How about (UNTESTED):

select

         count(case when order_date between '01-JAN-1996' and
                  '31-MAR-1996' then 1 else 0)  Q1-1996
        ,count(case when order_date between '01-APR-1996' and
                  '30-JUN-1996' then 1 else 0)  Q1-1996
         ...

-- 
Galen deForest Boyer
Sweet dreams and flying machines in pieces on the ground.
Received on Tue Jun 18 2002 - 22:38:07 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US