当前位置:网站首页>ORM aggregate query and native database operation
ORM aggregate query and native database operation
2022-07-06 04:40:00 【Legal procedures for working in banks】
1. Aggregate query
Classification is divided into whole table aggregation and grouping aggregation .
1.1 Whole table aggregation
First import from django.db.models import *
Aggregate functions Sum Avg Count Max Min
grammar :
MyModel.objects.aggregate( Outcome variable = Aggregate functions (’ Column ‘))
Return dictionary :{ Result variable name : value }
1.2 Group aggregation
Group first , Repolymerization
1.2.1 Group first
MyModel.objects.values(‘ Column 1’,’ Column 2‘)
1.2.2 use annotate polymerization
2. Native database operations
prevent sql Inject , Not recommended
raw return RawQuerySet Just cycle
Inquire about :
res = Book.objects.raw('select * from bookstore_book where id =%s'%(id))
2.1 The cursor
Operate the database completely across model classes , Check, modify and delete
2.1.1 Import cursor
from django.db import connection
2.1.2 establish cursor object
Usually use with sentence , Easy to release cursor resources
from django.db import connection
with connection.cusor() as cur:
cur.exectue('SQL',' Splicing parameter ')
边栏推荐
- Basic explanation of turtle module - draw curve
- How does computer nail adjust sound
- P2022 有趣的数(二分&数位dp)
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- [try to hack] John hash cracking tool
- Can Flink SQL read multiple topics at the same time. How to write in with
- cdc 能全量拉去oracle 表嘛
- 比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
- The value of two date types is subtracted and converted to seconds
- How to estimate the population with samples? (mean, variance, standard deviation)
猜你喜欢
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
How to estimate the population with samples? (mean, variance, standard deviation)
[tomato assistant installation]
Is the mode of education together - on campus + off campus reliable
coreldraw2022新版本新功能介绍cdr2022
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
Use sentinel to interface locally
二叉树基本知识和例题
The most detailed and comprehensive update content and all functions of guitar pro 8.0
View workflow
随机推荐
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
C. The third problem
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
How to estimate the population with samples? (mean, variance, standard deviation)
Lambda expression learning
ue5 小知识点 开启lumen的设置
[tomato assistant installation]
Hashlimit rate control
8. Static file
web工程导入了mysql驱动jar包却无法加载到驱动的问题
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Use sentinel to interface locally
npm命令--安装依赖包--用法/详解
cdc 能全量拉去oracle 表嘛
SQL注入漏洞(MSSQL注入)
CertBot 更新证书失败解决
[network] channel attention network and spatial attention network
Introduction to hashtable
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems