SQL grouping/counting 字符串拆分函数
SQL grouping/counting on a string split function
好的,我的原创是这个
select people, count(*)
from table
group by people
但有些人有多个人,因此此聚合不会为您提供 A、B、C 的纯计数,也不会为您提供每次迭代的计数
A 10
B 5
A, B 1
A, C 2
C 15
A, B, C 3
等等
这可以获取遗产中个人的完整列表 sql
select split(people,",") as person
from table
但是我不能在上面使用group by
select split(people,",") as person, count(*)
from table
group by person
给出错误
Cannot group by an aggregate.
我觉得解决方案是一个子查询,不知何故,但我不确定如何执行它
尝试用外部查询换行
select person, count(*)
from(
select split(people,",") as person
from table
) t
group by person
好的,我的原创是这个
select people, count(*)
from table
group by people
但有些人有多个人,因此此聚合不会为您提供 A、B、C 的纯计数,也不会为您提供每次迭代的计数
A 10
B 5
A, B 1
A, C 2
C 15
A, B, C 3
等等
这可以获取遗产中个人的完整列表 sql
select split(people,",") as person
from table
但是我不能在上面使用group by
select split(people,",") as person, count(*)
from table
group by person
给出错误
Cannot group by an aggregate.
我觉得解决方案是一个子查询,不知何故,但我不确定如何执行它
尝试用外部查询换行
select person, count(*)
from(
select split(people,",") as person
from table
) t
group by person