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.
I tend to use analytic functions to do this kind of query. Something like: