SQL拾遗

一。分组

1.Row_Number的用法

select row_number() over(order by field1) as row_number,* from t_table
其中over用来对于某列进行排序

2.Rank与dense_rank

生成的一个为不连续序号,另一个为连续的

3.ntile

select ntile(4over(order by field1) as bucket,* from t_table
对于序号进行分组

二。记录旋转

declare @t table(name varchar(20))
insert @t
select 'abc' union all
select 'xxx' union all
select 'xxx' union all
select 'ttt'

select * from @t
 

posted @ 2010-03-11 11:31  Johnnyliu  阅读(106)  评论(0编辑  收藏  举报