问题描述
RT,需要分组排名例如年度,销量,月度2009501200930220097042009NULL6200990920101001201015022010904按年度排名20099091(名次)2009704220095013200930242009NULL6520101502120101001220109043
解决方案
解决方案二:
该回复于2012-01-12 13:17:57被版主删除
解决方案三:
sqlrank()排名
解决方案四:
我需要的是分组时的排名
解决方案五:
-->测试数据:[TB]ifobject_id('[TB]')isnotnulldroptable[TB]gocreatetable[TB]([年度]int,[销量]int,[月度]int)insert[TB]select2009,50,1unionallselect2009,30,2unionallselect2009,70,4unionallselect2009,null,6unionallselect2009,90,9unionallselect2010,100,1unionallselect2010,150,2unionallselect2010,90,4select*,flag=RANK()over(PARTITIONBY[年度]orderby[销量]desc)from[TB]orderby[年度],[销量]desc/*年度销量月度flag-----------------------------------------------------200990912009704220095013200930242009NULL6520101502120101001220109043(8行受影响)*/droptable[TB]