select * from (
SELECT a.Id,a.MoldNames,b.ItemValue,d.InsName,row_number() over(partition by a.Id,b.Id order by d.InsertTime desc) as seq
FROM Base_Mold as a
LEFT JOIN Doc_CheckItem as b on b.ParentId=a.Id
left join Doc_CheckInspectionRecord as d on d.CheckItemId=b.Id) as f where f.seq=1
Case when then end
strSql.Append(@"select a.*,case when a.Type='02' then(select MoldNames from Base_Mold as b where a.ObjectID =b.Id ) when (a.Type ='03' OR a.Type='04') then(select UserName from User_Detail as c where a.ObjectID=c.Id) end CheckNameEd,b.GoodsName as ProName,b.CustomerName as CustName,b.SaleOrderCode as OrderNum ,c.RealName as CheckName from Doc_InspectionRecord as a");
strSql.Append(" left join v_SubDispatchingInfo as b");
strSql.Append(" on a.DispatchingItemID=b.SubId ");
strSql.Append(" left join Base_User as c");
strSql.Append(" on a.InspectionUser=c.UserId");