当前位置:网站首页>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 ')

边栏推荐
- SQL注入漏洞(MSSQL注入)
- hashlimit速率控制
- Complete list of common functions of turtle module
- [detailed steps of FreeRTOS shift value for the first time]
- 二叉树基本知识和例题
- Lombok principle and the pit of ⽤ @data and @builder at the same time
- web工程导入了mysql驱动jar包却无法加载到驱动的问题
- Bubble sort
- Programmers' position in the Internet industry | daily anecdotes
- How does computer nail adjust sound
猜你喜欢
![[05-1, 05-02, 05-03] network protocol](/img/25/2e9ccc3f31a1fd46c9ab643d48064b.jpg)
[05-1, 05-02, 05-03] network protocol

Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill

CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)

During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input

电脑钉钉怎么调整声音

Recommendation | recommendation of 9 psychotherapy books

二叉树基本知识和例题

Programmers' position in the Internet industry | daily anecdotes

Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
![[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University](/img/22/ead74bc121a64910ef6ef374cd029b.png)
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
随机推荐
SharedPreferences 源码分析
How does vs change the project type?
牛顿插值法
[HBZ sharing] how to locate slow queries in cloud database
flink sql 能同时读多个topic吗。with里怎么写
hashlimit速率控制
动态规划(树形dp)
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
Use sentinel to interface locally
Platformio create libopencm3 + FreeRTOS project
[try to hack] John hash cracking tool
解决“C2001:常量中有换行符“编译问题
Fuzzy -- basic application method of AFL
VPP performance test
Etcd database source code analysis -- etcdserver bootstrap initialization storage
Bubble sort
关于imx8mp的es8316的芯片调试
SharedPreferences source code analysis
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Easyrecovery靠谱不收费的数据恢复电脑软件