mysql中 中文想要按拼音排序直接写成order by 字段名称 不好用,所以一般都会写成ORDER BY convert(字段名称 using gbk)。那使用sqlalchemy连接数据库查询数据 不想直接写sql语句 都是怎么写的?
我是这样写的:
from sqlalchemy import sql
session.query(User).order_by(sql.func.CONVERT(sql.literal_column('user_name USING gbk'))).all()