在ponyorm中按子串分组

时间:2018-02-24 04:03:24

标签: python mysql ponyorm

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

我想在PonyORM中实现它,任何人都可以帮我编写查询语句吗?提前致谢

1 个答案:

答案 0 :(得分:0)

实际上很容易

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

kozlovsky在github

回答

关于使用此查询对象:

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