--这是某报表里面更新临时表的品类组内排名的update写法
Update tGMRptBrandSum_Tmp A
Set Lpm=(Select Lpm From(Select ClsCode,BrandCode,rank() over (partition by ClsCode order by SaleSum desc) as Lpm
From tGMRptBrandSum_Tmp Group By ClsCode,BrandCode,SaleSum)
Where A.ClsCode=ClsCode And A.BRANDCODE=BrandCode)
Where exists(Select Lpm From
(Select ClsCode,BrandCode,rank() over (partition by ClsCode order by SaleSum desc) as Lpm
From tGMRptBrandSum_Tmp Group By ClsCode,BrandCode,SaleSum)
Where A.ClsCode=ClsCode And A.BRANDCODE=BrandCode);
Rank()--排名
Over --定义范围声明
partition by ClsCode --以哪些字段分组
order by --排序字段
外事绝不问谷歌,问老牛就行了
内事绝不问百度,问荣工就行了