我试图在ClickHouse中返回表中的所有列,但是我想将Program
中的students
作为一个字段进行计数.理想情况下,查询应该返回University, Student, Program, student_count
.计数将是有多少个‘程序’以University
为单位进行分组.下面是一个查询示例
SELECT
University,
Program,
Student,
COUNT(Program) as student_count
FROM
table
GROUP BY
University
示例数据:
| University | Student | Program |
| ----------- | --------- | --------- |
| University A| Student 1 | Program A |
| University A| Student 2 | Program A |
| University A| Student 3 | Program B |
| University B| Student 4 | Program A |
| University B| Student 5 | Program B |
所需日期:(用谷歌翻译翻译)
| University | Student |Program |student_count|
| ----------- | ---------| -------- | ----------- |
| University A| Student 1| Program A|2 |
| University A| Student 2| Program A|2 |
| University A| Student 3| Program B|1 |
| University B| Student 4| Program A|1 |
| University B| Student 5| Program B|1 |
我的问题是,ClickHouse有可能做到这一点吗?如果可能,它将如何实现?