SQL函数分类新思路:基于计算上下文的PostgreSQL速查表
突破传统按数据类型分类的局限,提出按计算详细级别划分SQL函数的新思路——从行级计算到聚合计算,帮你建立更清晰的高级分析框架。
SQL 分类
1. 主流的函数分类方法及其局限
目前市面上主流的函数分类方法是按照函数引用的字段类型进行划分的。
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
📊 聚合函数 (多行变一行)
| PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
📊 窗口函数 & JSON (上下文与结构)
| PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
| PortableText [components.type] is missing "block" | PortableText [components.type] is missing "block" |
2. 个人推荐的分类思路:基于计算的性质
您个人推荐的分类思路是按照计算的性质,即函数计算所处的环境或上下文(Context),也就是其完成计算的详细级别来划分。
通过这种方式,您可以将函数分为两个最核心的类别:
行级别计算的特点是:计算是一行一行(Row by Row)完成的。计算结果绝不会跨行出现。
聚合函数与行级别函数不同,其计算必然跨行。
3. 通用计算(Expression)的定位
为了使函数分类体系更加清晰,您将既可以在明细行上做,也可以在聚合之后做的通用计算,独立出来放到了表达式(Expression)体系中。
通过将这些不限定引用类型或涉及上下文判断的复杂计算归入“表达式”中(例如 Tableau 中的 Fixed LOD 和 PowerBI 中的 Calculate),您的核心函数分类就清晰地聚焦在“在明细上完成”或“为聚合而处理”的计算上。
总结来说,您的函数分类思路是从传统的面向数据类型,升级到面向计算上下文(或详细级别)的高级分析框架。
这就像将一个图书馆的图书不再仅仅按“纸张类型”分类(如硬皮书、软皮书),而是按“读者使用场景”分类(如在阅览室借阅的、可带回家的),从而提供了一个更贴合分析需求和计算环境的体系。
📖 相关文章
● SQL 别裁新解:PostgreSQL函数分类速查表
● 基于RFM模型与Tableau Prep NTILE函数的旅客价值分层实现
● 8.1 计算的演进及分类:从Excel、SQL到Tableau
● 用Tableau画改进版幂函数柱状图
● Tableau计算回流客户:参数筛选 vs 表关联,哪个更高效?
——————————————————————————————
No comments yet