日期:2014-05-17 浏览次数:20597 次
--05以上可以用partition by然后取前5
------解决方案--------------------
with customer as ( 客户姓名, 客户类型, row_number() over(partition by 客户类型 order by getdate()) as V_rank ) select * from customer where v_rank<=5
------解决方案--------------------
;with aaa as ( select row_number() over(partition by [客户类型] order by newid()) as rowindex,* from customer ) select * from aaa where rowindex<6
------解决方案--------------------
CREATE TABLE customer ( customername VARCHAR(100), customertype INT ) GO INSERT INTO customer SELECT '赵三',1 UNION SELECT '钱三',1 UNION SELECT '孙三',1 UNION SELECT '李三',1 UNION SELECT '周三',1 UNION SELECT '吴三',1 UNION SELECT '郑三',2 UNION SELECT '王三',2 UNION SELECT '赵三',2 UNION SELECT '钱三',2 UNION SELECT '孙三',2 select customername, customertype from customer t where (select count(*) from customer where customertype=t.customertype and customername > t.customername )<3 ORDER BY customertype
------解决方案--------------------