Copy codeThe Code is as follows:
Select to_char (date_published, 'yyymmm ') yo from blog group by yo;
Convert to sqlalchemy statement
You can use extract ()
Copy codeThe Code is as follows:
In [3]: year_field = db. func. extract ('Year', ArticleModel. date_published)
In [4]: month_field = db. func. extract ('month', ArticleModel. date_published)
In [5]: yonth_field = year_field * 100 + month_field
In [6]: print db. session. query (yonth_field.label ('yonth'), db. func. count (1). group_by ('yonth ')
Select extract (year FROM article_meta.date_published) *: param_1 + EXTRACT (month FROM article_meta.date_published) AS yonth, count (: param_2) AS count_1
FROM article_meta JOIN article ON article_meta.id = article. id GROUPBY yonth
You can also use func to directly call functions or stored procedures supported by the database.
Copy codeThe Code is as follows:
Yonth = db. func. to_char (ArticleModel. date_published, 'yyyml'). label ('yonth ')
Archive_list = (db. session. query (yonth,
Db. func. count (1). group_by ('yonth'). all ())