当前位置:网站首页>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:
边栏推荐
- MongoDB permission verification is turned on and mongoose database configuration
- 看图识字,DELL SC4020 / SCv2000 控制器更换过程
- .net (C#) get year month day between two dates
- 软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
- 找不到DiscoveryClient类型的Bean
- 【LeetCode】双指针题解汇总
- 数据类型及输入输出初探(C语言)
- 软件质量评估的通用模型
- 软件测试面试题:负载测试、容量测试、强度测试的区别?
- [Cloud Native--Kubernetes] Pod Controller
猜你喜欢
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
SQL association table update
what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
leetcode:266. 回文全排列
Three tips for you to successfully get started with 3D modeling
oracle创建用户
简单的顺序结构程序(C语言)
软件开发工具的技术要素
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
随机推荐
2022杭电多校第三场 K题 Taxi
The master teaches you the 3D real-time character production process, the game modeling process sharing
测试经理要不要做测试执行?
Chinese and Japanese color style
LeetCode Hot 100
MAUI Blazor 权限经验分享 (定位,使用相机)
2022多校第二场 K题 Link with Bracket Sequence I
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
Modelers experience sharing: model study method
2022杭电多校 第三场 B题 Boss Rush
软件测试面试题:网络七层协仪具体?
【LeetCode】图解 904. 水果成篮
10 种常见的BUG分类
倒计时1天!8月2日—4日与你聊聊开源与就业那些事!
《MySQL入门很轻松》第2章:MySQL管理工具介绍
tiup uninstall
[Cloud Native--Kubernetes] Pod Controller
软件测试面试题:负载测试、容量测试、强度测试的区别?
E - Distance Sequence (前缀和优化dp
2022牛客多校训练第二场 J题 Link with Arithmetic Progression