当前位置:网站首页>gorm joint table query - actual combat
gorm joint table query - actual combat
2022-08-05 00:21:00 【Jingxing three thousand】
gorm table query - actual combat
Origins
- Technology required to do a project requirement encountered by a government project
- The background of the requirement is probably as follows: there is a
workers
table, aworker_records
table, the information of the staff is recorded in the workers table, and the staff will punch in when they go to work, and the punch record is in this worker_records table
The fields required in the workers table are as follows | The fields required in the worker_records table are as follows |
---|---|
gzryxm - meaning: name of staff | gzrxm——means: name of worker |
gzrysjh——means: staff phone number | gzrsjh——means: mobile phone number of worker |
gzrysfz——means: staff ID card | gzrsfz——means: worker ID card |
Unique ID number
Requirements: Get the name, mobile phone number, ID number of the person who hasn't punched the card
The drawing is as follows
gorm implementation
db.Model(&Worker{}).Select("workers.csbh,workers.gzryxm,workers.gzrysjh,workers.gzrysfz").Joins("left join worker_records on workers.gzrysfz = worker_records.gzrsfz").Where("worker_records.gzrsfz", nil).span>Scan(¬ClockedInPeopleAll)
MySQL native implementation
SELECT w.gzryxm,w.gzrysjh,w.gzrysfzFROM workers wLEFT JOIN worker_records wrON w.gzrysfz = wr.gzrsfzWHERE wr.gzrsfz IS NULL
This fulfills the requirements.
Extended
Two-table join table query can be divided into seven types, see the network diagram as follows:
边栏推荐
- 软件测试面试题:做好测试计划的关键是什么?
- 软件质量评估的通用模型
- 软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
- What is next-generation modeling (with learning materials)
- 论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
- uinty lua 关于异步函数的终极思想
- lua 如何 实现一个unity协程的工具
- 【云原生--Kubernetes】调度约束
- 2022杭电多校第三场 K题 Taxi
- Essential knowledge for entry-level 3D game modelers
猜你喜欢
oracle创建用户以后的权限问题
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
TinyMCE disable escape
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
node使用redis
电子行业MES管理系统的主要功能与用途
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
Mysql_13 事务
子连接中的参数传递
First, the basic concept of reptiles
随机推荐
国内网站用香港服务器会被封吗?
软件测试面试题:系统测试的策略有?
【Unity编译器扩展之进度条】
Mathematical Principles of Matrix
【idea】idea配置sql格式化
【Valentine's Day special effects】--Canvas realizes full screen love
动态上传jar包热部署
oracle创建用户
软件测试面试题:负载测试、容量测试、强度测试的区别?
《MySQL入门很轻松》第2章:MySQL管理工具介绍
Detailed explanation of common DNS resource record types
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
SQL association table update
Cloud native - Kubernetes 】 【 scheduling constraints
软件测试面试题:网络七层协仪具体?
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?
2022牛客多校第三场 J题 Journey
matlab中rcosdesign函数升余弦滚降成型滤波器
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP