create table `fact_refund`(
`id` int(10) NOT NULL AUTO_INCREMENT
,`RefundDate` varchar(30) NOT NULL DEFAULT ''
,`RefundCreateDate` varchar(30) NOT NULL DEFAULT ''
,`OrderInfoID` int(10) NOT NULL DEFAULT '0'
,`ProductCode` varchar(100) NOT NULL DEFAULT ''
,`ProductName` varchar(1000) NOT NULL DEFAULT ''
,`SiteName` varchar(100) NOT NULL DEFAULT ''
,`Currency` varchar(100) NOT NULL DEFAULT ''
,`ListingID` varchar(100) NOT NULL DEFAULT ''
,`SellerAccountID` int(10) NOT NULL DEFAULT '0'
,`BuyerAccount` varchar(600) NOT NULL DEFAULT ''
,`BuyerName` varchar(600) NOT NULL DEFAULT ''
,`SalesPlatformID` int(10) NOT NULL DEFAULT '0'
,`ProductQuantity` int(10) NOT NULL DEFAULT '0'
,`ProductPrice` decimal(10,2) NOT NULL DEFAULT '0.00'
,`Status` int(5) NOT NULL DEFAULT '0'
,`RefundType` varchar(100) NOT NULL DEFAULT ''
,`RefundQty` int(10) NOT NULL DEFAULT '0'
,`RefundTotalQty` int(10) NOT NULL DEFAULT '0'
,`RefundPrice` decimal(20,2) NOT NULL DEFAULT '0.00'
,`RefundTotalPrice` decimal(20,2) NOT NULL DEFAULT '0.00'
,`PaymentTypeID` int(5) NOT NULL DEFAULT '0'
,`GUID` varchar(50) NOT NULL DEFAULT ''
,`CurrencytoUSDRate` decimal(10,4) NOT NULL DEFAULT '0.0000'
,`PaymentDate` varchar(30) NOT NULL DEFAULT ''
,`OrderDate` varchar(30) NOT NULL
,PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into fact_refund
select
null as id
,t1.last_upd_date as RefundDate
,t1.create_date as RefundCreateDate
,COALESCE(t3.OrderInfoID,t2.OrderInfoID,0) as OrderInfoID
,COALESCE(t3.ProductCode,'') as ProductCode
,COALESCE(t3.ProductName,'') as ProductName
,COALESCE(t3.SiteName,'') as SiteName
,COALESCE(t3.Currency,'') as Currency
,COALESCE(t3.ListingID,'') as ListingID
,COALESCE(t3.SellerAccountID,0) as SellerAccountID
,COALESCE(t3.BuyerAccount,'') as BuyerAccount
,COALESCE(t3.BuyerName,'') as BuyerName
,COALESCE(t3.SalesPlatformID,0) as SalesPlatformID
,COALESCE(t3.ProductQuantity,0) as ProductQuantity
,COALESCE(t3.ProductPrice,0.00) asProductPrice
,COALESCE(t1.status,'') as Status
,COALESCE(t1.RefundType,'') as RefundType
,COALESCE(t2.RefundQty,'') as RefundQty
,COALESCE(t1.Quantity,'') as RefundTotalQty
,COALESCE(t2.RefundPrice,0.00) as RefundPrice
,COALESCE(t1.RefundPrice,0.00) as RefundTotalPrice
,COALESCE(t1.PaymentTypeID,0) as PaymentTypeID
,COALESCE(t3.GUID,'') as GUID
,COALESCE(t3.CurrencyToUSDRate,0.0000) as CurrencytoUSDRate
,COALESCE(t3.PaymentDate,'') as PaymentDate
,COALESCE(t3.OrderDate,'') as OrderDate
from data_warehouse_origin.refundmentinfo_refund_info t1
left join data_warehouse_origin.refundmentinfo_orderpaypalrefund t2
on t1.id = t2.PayPalRefundID
left join data_warehouse.fact_order t3
on t2.OrderInfoID = t3.OrderInfoID