• 窗口函数ntile()


    一直没实际的需求而使用ntile(),今天看了下,就是按序号分组的意思。

    还是以student表为例

    select ntile(3) over (order by score desc) as zu,
           name,
           score,
           province
    from student

    image

    一共13行数据,分三组,第一组就是5;

    那我们看分成五组结果如何呢?

    image

    分成五个组,前面1,2,3组是三个,后面两个组是2个。

    还可以使用ntile() over (partition by province order by score desc),先按province分再分组

    image

  • 相关阅读:
    Git 游离态的一次问题解决
    idea每次新建项目的默认路径
    springboot 整合 freemarker
    Linux 学习网站
    springtask 基本使用和 cron 表达式
    volatile 关键字 和 i++ 原子性
    python 自动补全
    nagios维护之常见问题
    nagios维护之添加监控
    windows下python文件与文件夹操作
  • 原文地址:https://www.cnblogs.com/cnmarkao/p/3756876.html
Copyright © 2020-2023  润新知