django的orm多表查询作业第五题答案(django orm多表查询)

网友投稿 350 2022-08-29


django的orm多表查询作业第五题答案(django orm多表查询)

5.每个作者出版的所有书的最高价格以及最高价格的那本书的名称.

用django的模型类写不出来的,只能用原生sql写这题关于第五题,mysql5.7及以上版本,使用下面的答案

set sql_mode='STRICT_TRANS__TABLES';#先将当前会话的sql_mode的only_full_group_by模式去掉 第一种写法加limit: select * from (SELECT app01_book.xx,app01_book.price,app01_author.id from app01_author INNER join app01_book_authors on app01_author.id = app01_book_authors.author_id INNER JOIN app01_book on app01_book_authors.book_id = app01_book.id ORDER BY app01_book.price desc LIMIT 100) as t GROUP BY t.id; 第二种写法加having:select * from (SELECT app01_book.xx,app01_book.price,app01_author.id from app01_author INNER join app01_book_authors on app01_author.id = app01_book_authors.author_id INNER JOIN app01_book on app01_book_authors.book_id = app01_book.id HAVING 1=1 ORDER BY app01_book.price desc) as t GROUP BY t.id;

5.6版本使用下面的答案

select * from (SELECT app01_book.xx,app01_book.price,app01_author.id from app01_author INNER join app01_book_authors on app01_author.id = app01_book_authors.author_id INNER JOIN app01_book on app01_book_authors.book_id = app01_book.id ORDER BY app01_book.price desc) as t GROUP BY t.id;

-------------------------------------------

个性签名:代码过万,键盘敲烂!!!

如果觉得这篇文章对你有小小的帮助的话,记得“推荐”哦,博主在此感谢!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:django学习第十天---ajax请求和JsonResponse(django jquery ajax)
下一篇:java设计模式七大原则之迪米特原则详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~