日期:2014-05-18  浏览次数:20479 次

求助一SQL语句统计以6个月为周期,连续4个月内业绩都进入15名的信息.
一、求助一SQL语句统计以6个月为周期,连续4个月内销售额(StyleSalesAmount)都进入15名的信息.
二、求助一SQL语句统计以6个月为周期,连续4个月内销售额(StyleSalesAmount)都进入16-30名的信息.
三、求助一SQL语句统计以6个月为周期,连续4个月内销售额(StyleSalesAmount)都进入30名的信息.

如:表StyleReport,字段信息如下:
Rkey(类型代号) StyleSalesAmount(销售额) StyleNetSalesAmount(净收入) StyleRate(占有率) StyleDate(销售月份)

StyleRkey Rkey StyleSalesAmount StyleNetSalesAmount StyleRate StyleDate
1 8626 2260919.88 2260919.88 6.25% 2011-01
2 8698 2234165.31 2234165.31 6.18% 2011-01
176 8698 918445.06 918445.06 6.02% 2011-02
178 8626 711834.36 711834.36 4.66% 2011-02
491 8698 2752999.43 2752999.43 7.50% 2011-05
492 8626 2337684.80 2337684.80 6.37% 2011-05

------解决方案--------------------
SQL code
with cte as
(select row_number() over(partition by StyleDate order by StyleSalesAmount desc) no,*
 from tb where StyleDate<'2011-07')

select * from cte where no<16
select * from cte where no between 16 and 30
select * from cte where no<30

------解决方案--------------------
探讨
条件描述有些不准确,只需要查询出六个月内有四个月符合上述要求记录信息。(不需要四个月连续)

------解决方案--------------------
探讨
引用:
条件描述有些不准确,只需要查询出六个月内有四个月符合上述要求记录信息。(不需要四个月连续)


SQL code
select Rkey,count(*) ct from(
select Rkey,StyleDate,s from (
select row_number()over(partition by StyleDate order……