当前位置: 首页 > news >正文

SQL,将多对多的关联记录按行输出

数据库的Primary表和Secondary表有相同的结构,其中W、H、D是主键。Primary表:
NameWHD
Primary item 1100500300
Primary item 2100600300
Primary item 3200500300
Primary item 4100500300
Primary item 5100600300
Primary item 6200500300
Secondary表:
NameWHD
Secondary item 1100500300
Secondary item 2100600300
Secondary item 3200500300
Secondary item 4100500300
Secondary item 5100600300
Secondary item 6200500300
要求从两张表中找出符合条件W=100,H=500,D=300的记录,先输出Primay里的一行,再输出相关联的Secondary的每一行。
NameWHD
Primary item 1100500300
Secondary item 1100500300
Secondary item 4100500300
Primary item 4100500300
Secondary item 1100500300
Secondary item 4100500300

编写SPL代码:

A
1=sqlServer1.query("select * from Primary where W = 100 and H = 500 and D = 300")
2=sqlServer1.query("select * from Secondary where W = 100 and H = 500 and D = 300")
3=if(A2,A1.conj(~|A2))

A1、A2:执行简单SQL,条件查询。

A3:A2为空时返回空,A2不为空时,循环A1的每条记录 ~,合并 ~ 和 A2,最后再合并循环的结果。


http://www.mrgr.cn/news/5522.html

相关文章:

  • opencv-python图像增强十:图像色温调整
  • Github文件夹重命名|编程tips·24-08-22
  • 第11章 第6节 软件测试类型(软件评测师)
  • uniapp+vue3的defineProps传递
  • 防爆气象仪的工作原理
  • CTFHUB | web进阶 | JSON Web Token | 无签名
  • C# 泛型
  • 理解现代前端开发:从HTML到React的进化之路
  • 浅谈Spring Boot
  • Python 如何使用 functools 模块
  • Go RPC 和 gRPC 技术详解
  • 学习Math.random()的应用
  • 前端html+js实现懒加载的两种常见方法
  • 一文弄懂 LLM 结构化数据生成原理
  • 基于Python自动连接汕头大学校园网
  • Axios介绍;前后端分离开发的介绍;YAPI的使用;Vue项目简介、入门;Elementui的使用;nginx介绍
  • 支付宝开放平台-开发者社区——AI 日报「8 月23 日」
  • BaseCTF WEEK1 re复现-入土为安的第24天
  • halcon1
  • [Linux#40][线程] 线程控制 | 多线程