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

Home -> Community -> Mailing Lists -> Oracle-L -> Group/Sort by date field

Group/Sort by date field

From: <MooreMJ_at_DFO-MPO.GC.CA>
Date: Mon, 05 Feb 2001 11:37:36 -0800
Message-ID: <F001.002AADB8.20010205102906@fatcity.com>

Hi
I am wondering about some results I am getting back when I am querying based on date fields. I have a large table partitioned on source year. When I run the following query the results are not correct results, it seems to be grouping the year incorrectly.

select to_char(landed_dt,'YYYY'), count(distinct vessel_code),sum(landed_value)
 from landing_hist
 where to_char(landed_dt, 'YYYY') in ('1994','1995','1996')

  and source_year in ('1994','1995','1996')
 group by to_char(landed_dt, 'YYYY')
 order by to_char(landed_dt, 'YYYY')

When I run the query for individual years the data returned is correct and when I rewrite the query so that it is not being grouped by to_char(landed_dt,'YYYY') (see below) the results are correct.

select source_year, count(distinct vessel_code),
   sum(landed_value)
 from landing_hist

 where to_char(landed_dt, 'YYYY') in ('1994','1995','1996')   and source_year in ('1994','1995','1996')  group by source_year
 order by source_year

Can anyone help me out with what I am missing - it seems like it has to be something obvious - but I don't know what.

Thanks
Jane

--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author:
  INET: MooreMJ_at_DFO-MPO.GC.CA

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Mon Feb 05 2001 - 13:37:36 CST

Original text of this message

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