Home >Database >Mysql Tutorial >SQLServer ntile获取每组前10%的数据

SQLServer ntile获取每组前10%的数据

WBOY
WBOYOriginal
2016-06-07 18:04:371248browse

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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn