Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:57:53+00:00 2026-05-26T12:57:53+00:00

I have a table that contain some Inspection Data. Every commodity needs to be

  • 0

I have a table that contain some Inspection Data. Every commodity needs to be inspected every month. The goal here is to find the last inspected record for each month.

Table Inspection:

INSPECTION_I——–INSPECTION_TS

200————————— 10/20/2011

201—————————-10/24/2011

202—————————-10/26/2011

Table Product_Inspection:

INSPECTION_I——————ASSET_I

200————————————1000

201————————————2000

Table Box_Inspection

INSPECTION_I——–ASSET_I

202————————3000

Table Product

ASSET_I————ASSOCIATED_BOX_ASSET_I

1000—————————3000

Table BOX:

ASSET_I————OTHER_STUFF

3000——————–#####

Now in this case what I want is 201 and not 200. I tried to do MAX(to_char(inspection_ts, ‘mm/yyyy’)) but that is not helping. There is one more issue. For some reason, I keep getting the Cartesian in a case where a Product or a Box is inspected twice or more in a month. All I want is one inspection every month and it should be the last inspection for each month. I am really close to getting it but if someone can help, I would really appreciate it. I was able to get it done through a nested cursor but I don’t want that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:57:54+00:00Added an answer on May 26, 2026 at 12:57 pm

    I tend to use analytic functions to do this kind of query. Something like:

    with data as
    (
        select 1 product_id, 100 inspection_id, to_date('09/04/2011', 'MM/DD/YYYY') inspection_date from dual union all
        select 1 product_id, 101 inspection_id, to_date('09/14/2011', 'MM/DD/YYYY') inspection_date from dual union all
        select 1 product_id, 103 inspection_id, to_date('10/04/2011', 'MM/DD/YYYY') inspection_date from dual union all
        select 1 product_id, 105 inspection_id, to_date('11/01/2011', 'MM/DD/YYYY') inspection_date from dual union all
        select 2 product_id, 102 inspection_id, to_date('09/24/2011', 'MM/DD/YYYY') inspection_date from dual union all
        select 2 product_id, 104 inspection_id, to_date('10/05/2011', 'MM/DD/YYYY') inspection_date from dual
    )
    select *
    from 
    (
        select
            product_id,
            inspection_id,
            inspection_date,
            row_number() over (
                partition by
                    product_id,
                    trunc(inspection_date, 'MM') -- Month
                order by
                    inspection_date desc
            ) rn
        from
            data
    )
    where rn = 1 -- indicates last inspection date of the month for each product
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another basic Rails question: I have a database table that needs to contain references
I have data from a table in a database (string) that contain text and
I have a folder /Tables that contain all the table objects scripts. Some of
I have a Mysql table that has 12 columns. Some of them contain 20-30
I have a table that contains some blob fields that I don't want to
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have two functions to add and remove table rows that contain a form
I have seen apps that have table views that have rows that contain 2
I'm currently writing a filter for a selectable, I have some table cells that
I have a table that has a couple of cells that do not contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.