sql server 取记录时部分字段相同去除重复

来源:互联网 发布:mysql case when else 编辑:程序博客网 时间:2024/06/11 00:35
select b.StoreID,b.StoreName,b.SaleAreaName,b.ContactName,b.Tel,b.StoreTypeName,b.OrderCount,
       b.Price,b.ProductName,b.BrandID,b.BrandName,          
       b.ProductID, b.UserName,b.CheckTime
     from (select a.StoreID,
         a.StoreName,
         a.SaleAreaName,
         a.ContactName,
         a.Tel,
         a.StoreTypeName,
         a.OrderCount,
         a.Price,a.ProductName,a.BrandID,a.BrandName,
         a.ProductID,
         a.CheckTime,
         a.UserName,
--         count(1) over(partition by a.StoreID) as count_id,
--         count(1) over(partition by a.StoreID, a.ProductID) as count_price,
         row_number() over(partition by a.StoreID, a.ProductID order by a.CheckTime desc) as row_c
       from VTBasProductBrand a) b
   where b.row_c = 1
原创粉丝点击