Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query w/ MAX date for each unique item

GreenTek1234Feb 7 2018 — edited Feb 7 2018

Hi guys!

I'm attempting to write a pretty simple query. Goal is to extract the max ship date associated with a project number, resulting in a single line for each unique project. Unfortunately, the code is returning records for each ship date. Pretty sure there's a missing condition somewhere, but I'm stumped. Any ideas?

Query:

    SELECT  proj.name                  "Project Name"

    ,       proj.segment1              "Project Number"

    ,       TRUNC(To_DATE(max(oola.schedule_ship_date), 'DD-MON-YY')) "Oracle Ship Date"

    FROM   oe_order_lines_all oola

    ,      pa_projects_all proj                     

    WHERE  proj.project_id = oola.project_id

    AND    oola.flow_status_code IN ('AWAITING_SHIPPING','BOOKED', 'ENTERED', 'AWAITING_FULFILLMENT', 'AWAITING_RETURN', 'CLOSED')

    AND    proj.project_status_code not like 'CLOSED'

    AND    proj.segment1 like '650%'

   GROUP BY proj.name, proj.segment1, oola.schedule_ship_date

   ORDER BY proj.segment1

Output:

Project NameProject Number
Oracle Ship Date
Horse1231/1/2018
Horse1234/2/2018
Horse1236/3/2018
Pig2342/5/2018
Pig23412/10/2018
Monkey3455/25/2018
Monkey3456/19/2018
Monkey3456/28/2018

Desired Output:

Project NameProject NumberOracle Ship Date
Horse1236/3/2018
Pig23412/10/2018
Monkey3456/28/2018
This post has been answered by Jonathan Lewis on Feb 7 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2018
Added on Feb 7 2018
4 comments
1,222 views