USE [P21]
GO

/****** Object:  View [dbo].[mh_vw_last_sale]    Script Date: 10/31/2024 4:43:40 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create view [dbo].[mh_vw_last_sale] as

select * from (
select order_date, customer_id, item_id, unit_price , row_number() over (partition by customer_id, item_id order by order_Date desc) as rw_nm

from p21_view_oe_hdr oh
left outer join p21_view_oe_line ol on oh.order_no = ol.order_no

where projected_order <> 'y'
and rma_Flag <> 'y'
and isnull(oh.cancel_flag,'n') <> 'y'
and isnull(ol.cancel_flag, 'n') <> 'y'
and isnull(ol.disposition,'r') <> 'c'
and isnull(oh.delete_flag, 'n') <> 'y'
and isnull(ol.delete_flag, 'n') <> 'y'
 ) t1

 where rw_nm = 1 
GO

