Copy Code code as follows:
Select To_char (date_published, ' yyyymm ') Yo from blog Group by Yo;
Convert to SQLAlchemy statement
You can use Extract ()
Copy Code code 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]:p rint db.session.query (Yonth_field.label (' Yonth '), Db.func.count (1)). Group_by (' Yonth ')
SELECT EXTRACT article_meta.date_published *:p aram_1 + EXTRACT (month from article_meta.date_published) as Yonth, COUNT (:p aram_2) as Count_1
From Article_meta JOIN article on article_meta.id = Article.id GROUPBY yonth
You can also call a database-supported function or stored procedure directly via Func
Copy Code code as follows:
Yonth = Db.func.to_char (articlemodel.date_published, ' Yyyymm '). Label (' Yonth ')
Archive_list = (Db.session.query (Yonth,
Db.func.count (1)). Group_by (' Yonth '). All ())