鍍金池/ 問答/Python  數(shù)據(jù)庫  網(wǎng)絡(luò)安全/ sqlalchemy 查詢數(shù)據(jù),按照字段中數(shù)據(jù)(中文)轉(zhuǎn)拼音(升序)排序

sqlalchemy 查詢數(shù)據(jù),按照字段中數(shù)據(jù)(中文)轉(zhuǎn)拼音(升序)排序

1.sqlalchemy 查詢數(shù)據(jù),按照字段中數(shù)據(jù)(中文)轉(zhuǎn)拼音(升序)排序
2.已知sqlalchemy中有func.convert和sql.func.CONVERT方法,導(dǎo)入方式為

from sqlalchemy import func
from sqlalchemy import sql

下面是我的實現(xiàn)方式

self.db.query(Table).order_by(
            sql.func.CONVERT(sql.literal_column('VARCHAR(8)'), 
            Table.department_name, sql.literal_column('8'))).all()

結(jié)果提示:
ProgrammingError: (_mysql_exceptions.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(8), Table.department_name, 8)

不知道如何實現(xiàn)?

回答
編輯回答
涼心人

這里有參考的鏈接https://stackoverflow.com/que...,但是不能解決問題

2017年11月24日 11:54