当前位置:网站首页>ORM--分组查询,聚合查询,查询集QuerySet对象特性
ORM--分组查询,聚合查询,查询集QuerySet对象特性
2022-07-07 07:17:00 【chuntian_tester】
1.分组查询
1.1.使用 QuerySet对象.values(‘父表主键id’).annotate(聚合函数(‘从表模型类名小写')
1.2.会自动连接主从表,以外键字段作为分组条件
2.聚合运算
2.1.使用 QuerySet对象.aggregate(聚合函数('字段名')) 方法,返回字典数据
2.2.返回的字典数据中的key为 字段名__聚合函数名 小写
2.3.可以使用关键参数形式,返回的字典数据中的key为关键字参数名
qs = Projects.objects.filter(full_name__contains='x').aggregate(Count("id"))
qs = Projects.objects.filter(full_name__contains='x').aggregate(count=Count("id"))
3.查询集QuerySet对象的特性:
3.1 支持链式调用
可以在查询集上多次调用filter(),exclude()方法
3.2 惰性查询
仅仅在使用数据时才执行Sql语句,为了提升数据库的读写性能
3.3 会执行Sql语句场景:
len(),count(),通过索引取值,切片,for循环,print等
边栏推荐
- HCIP 第一天 笔记整理
- 洛谷P2482 [SDOI2010]猪国杀
- [4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
- Application of C # XML
- How to solve the problem of golang select mechanism and timeout
- ViewPager2和VIewPager的区别以及ViewPager2实现轮播图
- [4g/5g/6g topic foundation -147]: Interpretation of the white paper on 6G's overall vision and potential key technologies -2-6g's macro driving force for development
- C# XML的应用
- 为什么安装mysql时starting service报错?(操作系统-windows)
- 大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
猜你喜欢
20排位赛3
Arthas simple instructions
Performance optimization record of the company's product "yunzhujia"
Switching value signal anti shake FB of PLC signal processing series
基础篇:带你从头到尾玩转注解
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
【原创】程序员团队管理的核心是什么?
Dynamics 365online applicationuser creation method change
使用BigDecimal的坑
JS reverse tutorial second issue - Ape anthropology first question
随机推荐
js逆向教程第二发-猿人学第一题
位操作==c语言2
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
第一讲:寻找矩阵的极小值
Performance optimization record of the company's product "yunzhujia"
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
Become a "founder" and make reading a habit
[untitled]
Bean 作⽤域和⽣命周期
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
能源路由器入门必读:面向能源互联网的架构和功能
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
What development models did you know during the interview? Just read this one
Flex flexible layout
HCIP 第一天 笔记整理
Lesson 1: finding the minimum of a matrix
如何成为一名高级数字 IC 设计工程师(5-2)理论篇:ULP 低功耗设计技术精讲(上)
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Sword finger offer II 107 Distance in matrix