我最近完成了SQLmodel文档,但是它没有告诉我如何使用group_by命令。我正在尝试以下操作:
SELECT reader_status, count(book_id)
FROM readerbook
WHERE reader_id=1
GROUP BY reader_id, reader_status将在SQLmodel代码中使用。
statement = select(
ReaderBook.reader_status, func.count(ReaderBook.book_id).label("count")
)这是我的代码。如何使用group_by "reader_id“条件?
发布于 2021-10-16 14:44:32
假设readerBook是表的变量,即
readerBook = Table(
...
)然后,您可以尝试以下操作。
statement = select([
readerBook.c.reader_status, func.count(readerBook.c.book_id).label("count")
])
.select_from(readerBook)
.group_by(readerBook.c.reader_id)https://stackoverflow.com/questions/69586541
复制相似问题