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

边栏推荐
猜你喜欢

【云原生--Kubernetes】调度约束

redis可视化管理软件Redis Desktop Manager2022

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

Will domestic websites use Hong Kong servers be blocked?

【LeetCode】Summary of Two Pointer Problems

Three tips for you to successfully get started with 3D modeling

论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》

【云原生--Kubernetes】Pod控制器

机器学习(公式推导与代码实现)--sklearn机器学习库

SV 类的虚方法 多态
随机推荐
软件测试面试题:手工测试与自动测试有哪些区别?
tiup update
2 用D435i运行VINS-fusion
【数据挖掘概论】数据挖掘的简单描述
找不到DiscoveryClient类型的Bean
tiup status
QSunSync 七牛云文件同步工具,批量上传
【LeetCode】Summary of Two Pointer Problems
软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
tiup telemetry
看图识字,DELL SC4020 / SCv2000 控制器更换过程
matlab中rcosdesign函数升余弦滚降成型滤波器
2022牛客多校第三场 J题 Journey
2022牛客多校训练第二场 L题 Link with Level Editor I
软件测试面试题:网络七层协仪具体?
软件测试面试题:软件验收测试的合格通过准则?
LeetCode Hot 100
标识符、关键字、常量 和变量(C语言)
MAUI Blazor 权限经验分享 (定位,使用相机)
简单的顺序结构程序(C语言)