当前位置:网站首页>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等
边栏推荐
- CDZSC_2022寒假个人训练赛21级(2)
- phpcms实现PC网站接入微信Native支付
- Sqlplus garbled code problem, find the solution
- JS reverse tutorial second issue - Ape anthropology first question
- 小程序弹出半角遮罩层
- flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
- How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
- La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
猜你喜欢
农牧业未来发展蓝图--垂直农业+人造肉
Esp8266 uses TF card and reads and writes data (based on Arduino)
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
【无标题】
[original] what is the core of programmer team management?
JS逆向教程第一发
Arthas simple instructions
EXT2 file system
Dynamics 365online applicationuser creation method change
使用BigDecimal的坑
随机推荐
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
Applet sliding, clicking and switching simple UI
【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
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...)
根据热门面试题分析Android事件分发机制(一)
小程序弹出半角遮罩层
使用BigDecimal的坑
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
AI从感知走向智能认知
内存==c语言1
Use 3 in data modeling σ Eliminate outliers for data cleaning
Lesson 1: finding the minimum of a matrix
Introduction to automated testing framework
thinkphp数据库的增删改查
Dynamics 365online applicationuser creation method change
Basic chapter: take you through notes
How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
Luogu p2482 [sdoi2010] zhuguosha
Internship log - day07
Win10安装VS2015