当前位置:网站首页>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等
边栏推荐
- 大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
- Arthas simple instructions
- Win10安装VS2015
- ViewPager2和VIewPager的区别以及ViewPager2实现轮播图
- How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
- **Grafana installation**
- 喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
- Check the example of where the initialization is when C initializes the program
- 哈夫曼编码压缩文件
- 高斯消元
猜你喜欢
随机推荐
First issue of JS reverse tutorial
Why are social portals rarely provided in real estate o2o applications?
Pytest learning - dayone
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
uboot机构简介
# Arthas 简单使用说明
PostgreSQL创建触发器的时候报错,
Sword finger offer II 107 Distance in matrix
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
14th test
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
Codeforces - 1324d pair of topics
CDZSC_ 2022 winter vacation personal training match level 21 (2)
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
大佬们,请问 MySQL-CDC 有什么办法将 upsert 消息转换为 append only 消
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
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
How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
Impression notes finally support the default markdown preview mode