当前位置:网站首页>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等
边栏推荐
- 【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
- Oracle installation enhancements error
- sql 里面使用中文字符判断有问题,哪位遇到过?比如value<>`无`
- Three years after graduation
- MySQL can connect locally through localhost or 127, but cannot connect through intranet IP (for example, Navicat connection reports an error of 1045 access denied for use...)
- Impression notes finally support the default markdown preview mode
- thinkphp3.2信息泄露
- 一大波开源小抄来袭
- How will fashion brands enter the meta universe?
- 小程序滑动、点击切换简洁UI
猜你喜欢

官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展

Use 3 in data modeling σ Eliminate outliers for data cleaning

一大波开源小抄来袭

Natapp intranet penetration

农牧业未来发展蓝图--垂直农业+人造肉
![[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](/img/21/6a183e4e10daed90c66235bdbdc3bf.png)
[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

Garbage disposal method based on the separation of smart city and storage and living digital home mode

Arthas simple instructions
![[Frida practice]](/img/20/fc68bcf2f55b140d6754af6364896b.png)
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform

Arcgis操作: 批量修改属性表
随机推荐
Communication mode between processes
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
Elaborate on MySQL mvcc multi version control
哈夫曼编码压缩文件
EXT2 file system
CDZSC_2022寒假个人训练赛21级(2)
Arcgis操作: 批量修改属性表
字节跳动 Kitex 在森马电商场景的落地实践
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
小程序弹出半角遮罩层
La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
【无标题】
JS逆向教程第一发
使用BigDecimal的坑
Software modeling and analysis
How will fashion brands enter the meta universe?
How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
剑指 Offer II 107. 矩阵中的距离