Skip to content

group-by #10

@Selflocking

Description

@Selflocking

赛题描述

实现数据分组功能。

分组功能也是数据库的基本功能之一,目的是为了方便用户查询数据结果,按照一定条件进行分组,方便分析数据。

按照一个或多个字段对查询结果分组,group by中的聚合函数不要求支持表达式。

需要支持having子句,因为聚合函数不能出现在where后面,所以增加having子句用于筛选分组后的数据。不过having只和聚合函数一起出现。

注意需要考虑分组字段为null的情况。

示例:

select t.id, t.name, avg(t.score),avg(t2.age) from t,t2 where t.id=t2.id group by t.id,t.name;
select count(id) from table group by name having count(id)>2;

赛题地址

https://open.oceanbase.com/train/TopicDetails?questionId=600004&subQesitonId=800022&subQuestionName=group-by

往年情况

2022年

  1. 支持group by功能,按照一个或多个字段对查询结果分组,group by中的聚合函数不要求支持表达式。
  2. 支持having子句,因为聚合函数不能出现在where后面,所以增加having子句用于筛选分组后的数据。
  3. having只和聚合函数一起出现。
  4. 需要考虑分组字段为null的情况。

测试用例示例:

select t.id, t.name, avg(t.score),avg(t2.age) from t,t2 where t.id=t2.id group by t.id,t.name;
select count(id) from table group by name having count(id)>2;

https://open.oceanbase.com/train/TopicDetails?questionId=500003&subQesitonId=700068&subQuestionName=group-by

2021年

支持group by功能。group by中的聚合函数也不要求支持表达式

https://open.oceanbase.com/train/TopicDetails?questionId=200001&subQesitonId=400018&subQuestionName=group-by

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions