当前位置:网站首页>ORM -- grouping query, aggregation query, query set queryset object properties
ORM -- grouping query, aggregation query, query set queryset object properties
2022-07-07 10:07:00 【chuntian_ tester】
1. Group query
1.1. Use QuerySet object .values(‘ Parent table primary key id’).annotate( Aggregate functions (‘ From the table model, the class name is lowercase ')
1.2. The master-slave table will be automatically connected , Take the foreign key field as the grouping condition

2. Aggregate operations
2.1. Use QuerySet object .aggregate( Aggregate functions (' Field name ')) Method , Return dictionary data
2.2. In the returned dictionary data key by Field name __ Aggregate function name A lowercase letter
2.3. Key parameter form can be used , In the returned dictionary data key Is the keyword parameter name
qs = Projects.objects.filter(full_name__contains='x').aggregate(Count("id"))

qs = Projects.objects.filter(full_name__contains='x').aggregate(count=Count("id"))

3. Query set QuerySet Properties of objects :
3.1 Support chain calls
You can call... Multiple times on a query set filter(),exclude() Method
3.2 Lazy query
Execute only when using data Sql sentence , In order to improve the read and write performance of the database
3.3 Will execute Sql Statement scenario :
len(),count(), Take value through index , section ,for loop ,print etc.
边栏推荐
- Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
- Gym - 102219J Kitchen Plates(暴力或拓扑序列)
- Can't connect to MySQL server on '(10060) solution summary
- 洛谷P2482 [SDOI2010]猪国杀
- The combination of over clause and aggregate function in SQL Server
- Introduction to automated testing framework
- ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
- Analyze Android event distribution mechanism according to popular interview questions (I)
- Agile course training
- 剑指 Offer II 107. 矩阵中的距离
猜你喜欢
随机推荐
Deadlock caused by non clustered index in SQL Server
网上可以开炒股账户吗安全吗
【原创】程序员团队管理的核心是什么?
Introduction to automated testing framework
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Parameter sniffing (2/2)
有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
Analyze Android event distribution mechanism according to popular interview questions (I)
ES6中的原型对象
Pit encountered by vs2015 under win7 (successful)
A wave of open source notebooks is coming
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Switching value signal anti shake FB of PLC signal processing series
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
uboot机构简介
“十二星座女神降临”全新活动推出
洛谷P2482 [SDOI2010]猪国杀
Apprentissage avancé des fonctions en es6
Basic chapter: take you through notes







