我可以帮助您进行SQLAlchemy查询的翻译。
我在实现这个MySQL查询时遇到了麻烦。
MySQL查询:
MySQL查询:
select u.post_id
from
user_record_cards u
where
u.record_card_id = 1 and u.count = 1
order by (select
count(*)
from
post_likes p
where
p.post = u.post_id)
我的SQLAlchemy查询如下:
obj = (
UserRecordCard.query
.filter(
UserRecordCard.record_card_id == 1,
UserRecordCard.count == 1
).order_by(
Like.query.filter(
Like.post == UserRecordCard.post_id
).count()
).all()
)
我的追踪信息如下:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 3453, in _literal_as_text
"SQL expression object or string expected."
ArgumentError: SQL expression object or string expected.