cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Question: Selecting earliest date time

Former Member
0 Kudos

I've a table that contains multiple transactions per any given day.

For each day of the month, I'm trying to find the earliest transaction possible. Below is my table data:

---------------------------------------------------------------
DATE                    |QUANTITY    |DIVISION    |  LOCATION
---------------------------------------------------------------
01-JAN-2008 12:42:01 AM |1234        |1           |  NORTH
01-JAN-2008 05:42:22 AM |1200        |1           |  NORTH
01-FEB-2008 01:42:01 AM |1123        |1           |  NORTH
01-FEB-2008 03:11:01 AM |985         |1           |  NORTH

So the question is, how do I select the EARLIEST transaction row for each given month,

This is my current SQL:

select       min(DATE),
             QUANTITY,
             DIVISION,
             LOCATION
             from TABLE
             group by QUANTITY, DIVISION, LOCATION

DATE field is a datatype "DATE" in Oracle database

My goal is to pretty much have the results shown as follows:

---------------------------------------------------------------
DATE                    |QUANTITY    |DIVISION    |  LOCATION
---------------------------------------------------------------
01-JAN-2008 12:42:01 AM |1234        |1           |  NORTH
01-FEB-2008 01:42:01 AM |1123        |1           |  NORTH

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Eric

Use the following query:

select DATE,

QUANTITY,

DIVISION,

LOCATION

from TABLE

where DATE in

(

select min(DATE) from TABLE

group by to_char(DATE,'YYYY')

)

group by DATE,QUANTITY, DIVISION, LOCATION

Hope this helps.

Regards

Nikhil

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Eric,

To get the earliest date values then insert a group on date field for each month and place all the fields in group header which gives you the first values (earliest dates) from your databsae fields. If you want to see thhe last dates then place all the fields in group footer,

Make sure the group order should be in ascending.

Regards,

Raghavendra

Former Member
0 Kudos

Hi Raghavendra.

Thanks for your suggestion but I'm not even close to putting my data in Crystal yet. This query is a small part of a much bigger query and I must have this puzzle the way it needs to be set. Otherwise, I will carry over a bunch of cartesians and duplicate data in to the main query.

Thanks.