Search code examples
pythonmysqlponyorm

Group by substring in ponyorm


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

I want to implement this in PonyORM, can anyone help me to write the query statement? Thanks in advance


Solution

  • Actually it's quite easy

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

    Answered by kozlovsky on github

    As to using this query object:

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