sql rank() 根据销售次数,生成排名列
2017-09-26 18:02
253 查看
people table schema id name sales table schema id people_id sale price
select p.id, p.name, count(p.id) as sale_count, Rank() over(order by count(p.id) desc) as sale_rank from people p, sales s where p.id = s.people_id group by p.id
结果如下:
id name sale_count sale_rank 9 Bethel Wuckert 18 1 4 Joannie Haley 16 2 7 Jailyn Hartmann V 10 3 10 Dr. Adolph Halvorson 10 3 5 Arlie Mitchell 10 3 6 Myra Tillman 10 3 1 Clarissa Shields V 9 7 8 Bobby Purdy 7 8 3 Gerson Goyette 6 9 2 Lois Marvin 4 10
相关文章推荐
- CodeSmith 5.0工具实例篇系列3——根据表生成新增的存储过程,针对MS Sqlserver
- sql 排名函数 rank() , row_number() , dense_rank() over
- 在sql中根据成绩显示学生排名
- SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较
- SQL 2005 四个排名函数(row_number、rank、dense_rank和ntile)的比较
- 根据数据库模块生成sql,pojo等
- SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较
- 根据基本表结构及其数据生成INSERT...的SQL
- 根据表名自动生成I/S/U/D的SQL语句,用于MSSQL2000/2005/2008
- Django中关于根据配置生成SQL语句的问题
- 根据反射生成SQL语句
- 动态SQL语句根据数据库列来查询数据,动态的生成列名称
- 根据数据生成 INSERT INTO ... 的 SQL (.Net C#, T-SQL Store Procedure 分别实现)
- CodeSmith 5.0工具实例篇系列4——根据表生成修改的存储过程,针对MS Sqlserver
- SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较
- 如何根据实体动态生成sql语句
- SQL 内置排名函数 DENSE_RANK
- SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较
- SQL-OVER与四种排名函数:ROW_NUMBER(),RANK(),DENSE_RANK(),NTILE()
- 根据表名自动生成INSERT,UPDATE,DELETE,SELECT的SQL语句