你可以看到我在这里想做什么:

select *, count(*) as count
from `songs`
where `band` REGEXP '^[^[:alpha:]]'
group by `band`
order by `band` asc

波段可以是:
avenged sevenfold
3 days grace
led zeppelin
98 mute
back street boys
beastie boys

我需要这样来选择第一个字符不是alpha的频带,并计算每个频带存在多少行。
不幸的是,我当前的查询似乎只是将所有匹配REGEXP的查询组合在一起。

最佳答案

不能选择不在group by子句中的列,也不能选择group函数(count,max…)
因为不需要对不需要的行进行分组,并且条件不超过组值(组函数的结果),所以可以使用where。
ASC是默认的排序感知,因此不需要指定它。

select band, count(*) as count
from songs
where band REGEXP '^[^[:alpha:]]'
group by band
order by band

关于sql - 选择并计数正则表达式按计数分组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4871023/

10-11 02:57