Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设您有一个书本表、一个学生表和一个映射表,显示了书籍和表之间的多对多关系。然后说你需要按借最多到最少的顺序对书籍进行排序。实现这一目标的最有效方法是什么?
如果对于每本书的借阅,在 Mapper 表中都有一条记录带有该书的 ID,则以下查询将按图书 ID 的借阅次数对图书 ID 进行排序:
SELECT BOOK_ID, COUNT(*) CNT FROM MAPPER GROUP BY BOOK_ID ORDER BY CNT DESC