表(商品名称,商品类,租赁时间)
请问现在要得到表中 某段时间内 某商品类中 商品租赁次数排名的前N个
显示 商品名称 和 租赁次数 ???、
谢谢,在线等待!!!

解决方案 »

  1.   

    select top N 商品名称,count(商品名称) 租赁次数  from 表 where 租赁时间 between time1 and time2 group by 商品名称  order by 租赁次数  desc
      

  2.   

    select top 10 商品名称,count(商品名称) 租赁次数  from 表 where 租赁时间 between time1 and time2 group by 商品类,商品名称  order by 租赁次数  desc
      

  3.   

    select top N 商品名称,租赁次数 from (select 商品类,商品名称,count(商品名称) 租赁次数  from 表 
    where 租赁时间 between time1 and time2 group by 商品类,商品名称) t  order by 租赁次数  desc