select type,min(code) from group_info
group by type;
注意:select 后面的列要在group by 子句中,或是用聚合函数包含,否则会有语法错误。
参考sql reference文档:
Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group.
分析一个聚合函数计算值基于一组行。他们不同于聚合函数返回多个行每组。
Analytic functions are the last set of operations performed in a query except for the final ORDER
BY
clause. All joins and all WHERE
, GROUP
BY
, and HAVING
clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER
BY
clause.
解析函数的最后一组操作中执行一个查询,除了最后的ORDER BY子句。所有连接和地方、GROUP BY和之前有条款完成分析处理功能。因此,解析函数只能出现在选择列表中或ORDER BY子句。
语法结构:
analytic_function ([ arguments ]) OVER (analytic_clause)
其中analytic_clause结构包括:
[ query_partition_clause ] [ order_by_clause [ windowing_clause ] ]
也就是:函数名( [ 参数 ] ) over( [ 分区子句 ] [ 排序子句 [ 滑动窗口子句 ] ])
这里PARTITION BY 引导的分区子句类似于聚组函数中的group by,排序子句可看成是select语句中的order by.