当前位置:网站首页>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
workerstable, aworker_recordstable, 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 NULLThis fulfills the requirements.
Extended
Two-table join table query can be divided into seven types, see the network diagram as follows:

边栏推荐
猜你喜欢

Essential knowledge for entry-level 3D game modelers

【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP

gorm联表查询-实战

数据类型及输入输出初探(C语言)

子连接中的参数传递

How to automatically push my new articles to my fans (very simple, can't learn to hit me)

性能测试如何准备测试数据

STC89C52RC的P4口的应用问题

Implementation principle of golang coroutine

could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
随机推荐
Will domestic websites use Hong Kong servers be blocked?
uinty lua 关于异步函数的终极思想
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
标识符、关键字、常量 和变量(C语言)
Huggingface入门篇 II (QA)
KT148A voice chip ic working principle and internal architecture description of the chip
2022杭电多校第一场 1004 Ball
Cloud native - Kubernetes 】 【 scheduling constraints
工业物联网 —— 新型数据库的召唤
软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
导入JankStats检测卡帧库遇到问题记录
tiup telemetry
僵尸进程和孤儿进程
IDEA 文件编码修改
软件测试面试题:软件都有多少种分类?
Mysql_13 事务
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
NMS原理及其代码实现
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
2022杭电多校第三场 K题 Taxi