select shopid 零售店,month 月份,sum(num) 销售数量
from sales
where month in (1...)
group by shopid ,month
order by month ,shopid ,sum(num) ???

解决方案 »

  1.   

    select shopid 零售店,month 月份,sum(num) 销售数量
    from sales
    where month in (1...)
    group by shopid ,month
    having sum(num)> 一定值
    order by month ,shopid ,sum(num)
      

  2.   

    create view t as
    select 1 a,4 b,120 c
    union 
    select 1 a,5 b,110 c
    union 
    select 1 a,6 b,80 c
    union 
    select 1 a,7 b,101 c
    union 
    select 1 a,8 b,120 c
    union 
    select 1 a,9 b,210 c
    union 
    select 1 a,10 b,21 c
    go
    select * into #t from t
    go--下面是取连续3个月大于100的资料
    select * from #t where exists( select t.* from
    (select a.a a1,a.b b1,a.c c1,b.a a2,b.b b2,b.c c2,c.a a3,c.b b3,c.c c3
     from #t a cross join #t b cross join #t c 
    where a.b<b.b and b.b<c.b) t
    where t.b1=t.b2-1 and t.b2=t.b3-1 and c1>100 and c2>100 and c3>100
    and (t.b1=#t.b or t.b2=#t.b or t.b3=#t.b)
    )drop view t
    go
    drop table #t
    go
      

  3.   

    我把问题说具体点吧:
    表名:shop    字段一:ID(int) month(varchar(10))Num(int)  ID      month    Num
      a        01      125
      a        02      198
      a        03      109
      a        04      160
      b        01      100
      b        02      106
      b        03      120
      b        04      160
      c        01      102
      c        02      98
      c        03      160
      c        04      130
      d        01      89
      d        02      110
      d        03      123
      d        04      150
    要求:查找出连续三个月数量都大于110的商家。