按子串分组

2024-09-28 21:39:02 发布

您现在位置:Python中文网/ 问答频道 /正文

select substr(word,1,1) as alpha, count(*) as count
from words
group by substr(word,1,1);

我想在PonyORM中实现这个,有人能帮我写查询语句吗?提前谢谢


Tags: fromalphabyascountgroup语句select
1条回答
网友
1楼 · 发布于 2024-09-28 21:39:02

其实很简单

query = select(
    (w.word[0], count())
    for w in Words
)

科兹洛夫斯基在github上回答

关于使用这个查询对象:

char_count_pair = list(query) 
for start_char, c in char_count_pair:
    print('char:', start_char, ', count:', c)

相关问题 更多 >