on 09-18-2008 11:40 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
80 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.