请教用sqlalchemy编写带order和SEPARATOR的group_concat语句。

现在需要将下面的语句转换成sqlalchemy的orm

select name, group_concat(price, order by price desc SEPARATOR '@') from test group by id

目前尝试下来order和SEPARATOR只能使用一个,当在第一个op后面加入第二个op的时候就会出现错误,不知道要如何编写,下面是我的写法,请赐教

select(
    name,
    func.group_concat(test.c.price).op('order by')(test.c.price)
)
.select_from(test)
.group_by(test.c.id)
阅读 2.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进