SQLServer ntile获取每组前10%的数据
编程学习 2021-07-05 16:33www.dzhlxh.cn编程入门
sqlserver2005有关键字ntile(x)和over(partition by.. order by..)子句配合.
比如获取每个表的前10%个字段。
select id , name , colid , rn from (
select * , rn = ntile (10 )
over (partition by id order by colorder )
from syscolumns )t where rn = 1
代码如下:
select id , name , colid , rn from (
select * , rn = ntile (10 )
over (partition by id order by colorder )
from syscolumns )t where rn = 1